2 ms·
I've seen the python ordered dict thing bite ex-python programmers over and over, in two different ways. First, assuming that the keys iterate in the order the
by bediger4000 2y ago
I've seen the python ordered dict thing bite ex-python programmers over and over, in two different ways.
First, assuming that the keys iterate in the order they're inserted, the cliche problem.
Second, marshalling JSON and unconsciously relying on the order in the JSON as hidden semantics. This makes it hard to understand the JSON as a human, as well as making what ought to be a portable format with other languages hard to reuse.
I've decided that Python is in the wrong here, not technically, but rather for encouraging humans to assume too much.
- zarzavat 2y agoAs the article says, reproducibility is important. If I have a bug on one run, I want to get that bug again on the second run. I want to be able to run the program again and again and have the same breakpoints hit in the same order with the same variables. If I run tests, I want them to give the same results each time. Randomness is bugs. Adding randomness to a language is adding bugs.
- dwattttt 2y agoYou can't avoid randomness and entropy, it's just something that's needed in too many places. For test repeatability though, whatever seeds a test run uses should be saved in order to repeat that test exactly. Best of both worlds: you get to cover weird bugs that only show up when stuff is in a certain order, and you can repeat the tests exactly.
- kokada 2y ago> First, assuming that the keys iterate in the order they're inserted, the cliche problem. Author here. I never assume that hash maps can be iterated in the same order as the insertion in any language, however the fact that in Go each iteration results in a different ordering is surprising.
- bediger4000 2y agoGood practice. My experience says that Python programmers consciously or unconsciously make that assumption often, which is bad practice.