5 ms·
Saving chars is often a poor reason to design a language feature.
by felipellrocha 9y ago
Saving chars is often a poor reason to design a language feature.
- johnwheeler 9y agoNope. It's called developer ergonomics.
- sevensor 9y agoThe annoyance here is a feature not a bug. Deeply nested dictionaries, in my experience, are a source of infinite KeyErrors. The problem with using a dictionary as a cheap object is that it's very easy for it to be an object you weren't expecting. Don't nest dictionaries in Python!
- Karunamon 9y agoSo then what are you supposed to deserialize nested data structures like JSON into? Dictionaries are the obvious "right" way, Python's annoying tooling aside.
- IanCal 9y agoNamedtuples or classes that represent the data, I'd suggest personally.
- pdonis 9y agoI would agree. Namedtuple has an asdict method so that reserialization to JSON is simple; you can do the same for a class.
- sevensor 9y agoI'd say that dictionaries are only the obvious "right" way if you're not planning on accessing any of their fields. Otherwise you have some set of expected fields, in which case you can define a namedtuple and avoid a vast array of nasty surprises. It's really easy to initialize a namedtuple from a dict (use ), as long as the dict has the right fields. If it doesn't, and you're planning on using its fields, the fact that this raises an exception is a good thing.
- msellout 9y agoWhat do you think of this library: https://github.com/selik/destructure https://github.com/selik/destructure It'll enforce schema and destructure the nested dict/list that results from JSON decoding.
- xapata 9y agoThat's like asking, "What data structure should I use for this CSV file?" Depends on the usage. Sometimes you leave them as nested dictionaries and lists. Sometimes you transform them into tabular data. Sometimes you aggregate, etc.
- swearfu 9y agoNo, it's called being terrible at your job. If you need to add complexity to your project just to save you some typing, you have no concept of what you're doing. It's like an accountant not understanding math.
- andybak 9y agoComplexity can hide in unexpected places and sometimes a dash of complexity in one place can make something in another place much simpler. I think this library has it's uses. I wouldn't use it uncritically but I wouldn't dismiss it either.
- omginternets 9y agoDeveloper ergonomics does not (always) mean "preventing effort". If that were true, there would be no type systems.
- rhizome 9y agoPart of ergonomics is simplicity about what the thing you're looking at actually is.