4 ms·
> If none of the training material says or implies that the keys will always be ordered, why would a programmer? Because people make mistakes.
by d_theorist 10y ago
> If none of the training material says or implies that the keys will always be ordered, why would a programmer?
Because people make mistakes.
- danso 10y agoPerhaps "should" is the better word. That is, a programmer should not assume the keys will be ordered.
- d_theorist 10y agoProgrammers should not try to access memory beyond the end of an array. They should not attempt to add ints and strings. They should not give a function a float when it expects a struct. But they do. So we try to design languages in such a way as to minimise the likelihood of these mistakes going unnoticed.
- noobiemcfoob 10y agoDesigning a language to minimize the likelihood of these mistakes is a motivation for language design, but usually far from the primary. "Programmers should not try to access memory beyond the end of an array" ^ Right, and when they do, it's called a logical bug, something to be fixed. A programmer relying on the incidental but unspecified behavior of a function would be making a similar mistake.
- d_theorist 10y agoI agree. But, we learned from C that the possibility of trying to access arbitrary parts of memory means that programs will end up trying to access parts they shouldn't. So, higher level languages like Python solve the problem by having memory-safe types like lists, which preclude the possibility of making this mistake. Similarly, if we randomise the ordering of keys in the dict then it's impossible for a programmer to make the mistake (consciously or unconsciously) of relying on ordering.
- noobiemcfoob 10y agoAt the cost of an additional processing step to scramble the keys. The balance between safeguarding ignorant or overactive programmers against the performance of a critical builtin type is not going to tip in that direction. The whole reason we can even have this discussion is because a new algorithm was developed to give us the increased performance in the first place.
- deleted 10y ago[deleted]
- tedmiston 10y ago> Programmers should not try to access memory beyond the end of an array. They should not attempt to add ints and strings. In Python, both of these raise an error to make it very explicit and obvious to the programmer, while this implicitly ordered keys bit can't.