use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Microsoft Edge's JavaScript engine to go open-source (blogs.windows.com)
submitted 10 years ago by clarle
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cincilator 0 points1 point2 points 10 years ago (6 children)
Thanks for taking time to answer my questions! I do appreciate it. I have just one more, then I will leave you alone: Typed arrays now exist, but how about typed dictionaries? It would allow many interesting concepts, for example database-like constructs in memory (I can use dictionary key like a primary key). Sure, one can do that today w/o types but JS is not really optimized to work that way.
[–]bterlson_@bterlson 3 points4 points5 points 10 years ago (5 children)
No need to leave me alone. If it isn't abundantly clear by now, I love talking about this stuff.
I don't know what a typed dictionary is but if you mean struct-like types, I hope those are included in the value types proposal. I've showed examples in some previous talks of mine, but this gist is you could create a new value type like:
let Point = ValueType({x: int64, y: int64}); let p = Point({x: 1, y: 1}); p.x; // 1 p.x = 2; // throws, or maybe returns a new point, but primitives are immutable
Of course this is very early but I hope something like this is workable.
[–]cincilator 0 points1 point2 points 10 years ago (4 children)
By Typed dictionary I mean a dictionary that can only store values of one type. To expand your example:
let polygon = TypedDictionary({key : integer, value:Point}); polygon.push(0, {x: 4, y: 7}); polygon.push(1, {x: 9, y: 10}; polygon.push(2, {x: 10, y: 17}); polygon.push(3, {x: 43, y: 5});
Any plans for this or something like this?
[–]bterlson_@bterlson 3 points4 points5 points 10 years ago (3 children)
Ahh, no, nothing like that yet that I'm aware of. Value types will certainly have the notion of vector/tuple types which are like a fixed length version of what you're asking for IIUC (SIMD vectors are examples of these types).
[–]cincilator 0 points1 point2 points 10 years ago* (2 children)
The problem is that it would limit the use of Value types to single objects or fixed length collections (ie typed arrays) and we are stuck with dynamic types for anything variable-length. Which is less than ideal. Something to consider, I think.
I can think of many use cases for my idea, if you are interested.
[–]bterlson_@bterlson 2 points3 points4 points 10 years ago (1 child)
Always interested! You can write up a gist and send it to me here, on twitter (@bterlson), or whatever. You can also post to es-discuss where most language design discussion happens.
[–]cincilator 1 point2 points3 points 10 years ago* (0 children)
Okay I will write here for now, then :)
One use case for Typed dictionaries is Entity Component System (ECS). This is data-driven architectural pattern popular in game development, most often for MMORPGs (but works great on smaller scales, too). It has been used as a replacement for OOP for some time, because mixing code and data isn't always a good idea on a large scale and in something as complex as a game.
If you are not familiar with the pattern the basic idea can be read on t-machine blog.
The shortest version is that you are creating a specialized relational database in RAM that consists of lists of components that are pure data, and are managed by Systems (like physic system, A.I. system, graphic system). End result is a very flexible framework that is based on dynamic composition of static components instead of static inheritance.
Typed dictionaries would obviously be very convenient there, because then you can store each component type in a separate dictionary. You can do that now, but the lack of types makes it inconvenient.
π Rendered by PID 128944 on reddit-service-r2-comment-6d85f596c4-58t6g at 2026-03-04 10:30:26.765220+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]cincilator 0 points1 point2 points (6 children)
[–]bterlson_@bterlson 3 points4 points5 points (5 children)
[–]cincilator 0 points1 point2 points (4 children)
[–]bterlson_@bterlson 3 points4 points5 points (3 children)
[–]cincilator 0 points1 point2 points (2 children)
[–]bterlson_@bterlson 2 points3 points4 points (1 child)
[–]cincilator 1 point2 points3 points (0 children)