4 ms·
Good explanation, thanks. I don't understand the advantage of the dollar syntax though. One character shorter, and makes it look more object-y, obscuring the p
by bruceboughton 13y ago
Good explanation, thanks.
I don't understand the advantage of the dollar syntax though. One character shorter, and makes it look more object-y, obscuring the perf difference.
- philh 13y ago(Two characters shorter.) At least in python, I would love to have syntax like that. (I would use :: instead of .$, but maybe :: is already used in C#.) Maybe it's just because I work with JSON a fair amount, but I frequently have an it-might-as-well-be-an-object that happens to be stored in a dict. And in theory, this means I need to do foo['bar']['baz'], which is hard to read and unpleasant to type. In practice, I often use a class which overloads attributes as being dict keys, so I can use foo.bar.baz, but this has its own problems. foo::bar::baz would be great.
- deleted 13y ago[deleted]
- thomasahle 13y agoI can see the use case for json, but hardly for anything else. What's wrong with just using a class here? Seems very similar to how it would work in java script.
- philh 13y agoAny time you have a dict with stringy keys that you know when writing the program. HTML attribute lists, database records, http request parameters, config files.
- mattmanser 13y agoIf you have a 'it might as well be an object' in C# it's trivial to change it to an object with anonymous types and then blam you've got all the advantages of statically typed objects. I, as the next programmer, would hate you if you started trying to use C# as a dynamic language by abusing dictionaries, you're losing all the advantages of C# while still suffering the disadvantages.
- philh 13y agoMy gut reaction is that I'm not sold. With HTTP requests for example, I want to say `if 'id' in params`, whereas `if hasattr(params, 'id')` feels unnatural. But I also know that I'm accessing `params['id']` at programming time, so it would be great to shorten that to `params::id`. (And this ignores converting to JSON. The library I use is designed to be passed dicts. You can teach it to accept arbitrary objects, but that's kind of a hack.)