4 ms·
> Once you go dict, you won't go back. This style of development is too easy, since dictionaries are baked into Python, and there are many facilities for workin
by Singletoned 10y ago
> Once you go dict, you won't go back. This style of development is too easy, since dictionaries are baked into Python, and there are many facilities for working effectively with them.
How is this an argument against using dictionaries?
After 10 years of Python development, I do find myself using dictionaries rather than objects, in just the way that the author proscribes, but I'm finding it to be a genuine pleasure.
- Roboprog 10y agoREPENT!!! :-) Yeah, get shit done, YAGNI, and all that. If needs wrapper, make one for repeated access types. If needs one or more bonafide objects for passing around, updating, and general good behavior, the make them as needed. Otherwise, there are 15 other little jobs that need coding, and we gotta move on.
- st3v3r 10y agoAnd what happens when one of those keys changes?
- niftich 10y agoYou change your code. Loose coupling a nice goal to aim for, but at the end of the day, somewhere deep down inside the code, you have to tightly couple to actually get anything done. Where that transition occurs is entirely programmer's discretion.
- st3v3r 10y agoBut there's a difference between changing it once when you serialize/deserialize it, and changing it every time you try to access the key.
- sidlls 10y agoWriting the code with the assumption that a key will change is on the same level with premature optimization, in my opinion. It might be reasonable to make the assumption for some keys. In these cases a function taking the data and key as arguments and returning the value is sufficient and appropriate. Frankly, if the code base is so littered with references to that specific data and key combination it might actually indicate a poor design.
- st3v3r 10y ago"Writing the code with the assumption that a key will change is on the same level with premature optimization, in my opinion." Considering how easy it is, and how often I've had keys change on me, I have to strongly disagree. "Frankly, if the code base is so littered with references to that specific data and key combination it might actually indicate a poor design." That's kinda the point of the article.
- Retra 10y agoA single constant will fix that problem.
- Singletoned 10y agoOr even just a search and replace...