News for hackers. Stuff that matters.
Re:Hyrum's Law by ncmncm on Saturday January 08, 2022 @09:37PM (#29859368)
This is an argument for maintainers to routinely change any unspecified behavior that doesn't cost (much) more to do it the new way, on each release. In a hash, tweak the hash function.

Downstream dependents breaking because they depend on undocumented behavior is their fault, not your fault. The sooner they break, the less it costs.

Re:Hyrum's Law by maerF0x0 on Sunday January 09, 2022 @03:00AM (#29861281)
Go does this with ranging over maps

    The iteration order over maps is not specified and is not guaranteed to be the same from one iteration to the next. If a map entry that has not yet been reached is removed during iteration, the corresponding iteration value will not be produced. If a map entry is created during iteration, that entry may be produced during the iteration or may be skipped. The choice may vary for each entry created and from one iteration to the next. If the map is nil, the number of iterations is 0.
[1]: https://go.dev/ref/spec#For_statements
Re:Hyrum's Law by allanrbo on Sunday January 09, 2022 @12:07AM (#29860366)
Exactly this approach is discussed in the Hyrum's Law chapter near the beginning of the SWE book :-) https://abseil.io/resources/swe-book
Re:Hyrum's Law by asddubs on Sunday January 09, 2022 @02:56AM (#29861261)
reminds me of chromium fork maintainers' complaints that it's hard patching parts of the codebase because things change drastically frequently, so you really have to pick and choose what you can afford to maintain.
Re:Hyrum's Law by tomrod on Sunday January 09, 2022 @12:38AM (#29860540)
Thanks for linking! Looking forward to reviewing.
Re:Hyrum's Law by zmj on Saturday January 08, 2022 @10:58PM (#29859905)
For a cheap, specific recommendation: if consumers of an api shouldn't depend on the order of a result set, randomize it.
Re:Hyrum's Law by vanviegen on Sunday January 09, 2022 @03:59AM (#29861613)
That would of course lead to consumers using your API to generate secret launch codes. Now your defacto spec mandates randomness.
Re:Hyrum's Law by zarzavat on Saturday January 08, 2022 @10:49PM (#29859844)
The other option is to consider non-determinism a bug and to fix it where possible. For instance, several language runtimes (JS, Python) now use dictionary collections that are enumerated in insertion order, removing a long standing source of non-deterministic behaviour.
Re:Hyrum's Law by sanxiyn on Sunday January 09, 2022 @07:25AM (#29862654)
This happened only after the discovery that for languages like Python, guaranteeing insertion order iteration is virtually free. As I understand how to do that wasn't widely known in, say, 2010, and how to do that for C++/Rust/etc is still unknown.
Re:Hyrum's Law by tialaramex on Sunday January 09, 2022 @08:01AM (#29862838)
It's not so much that it's free, as that what they were doing before to implement an unordered dict was so terrible that by comparison a reasonable design for an ordered dict is cheaper, so, why not? The options were:

* Existing design: Unordered behaviour confuses new programmers, Slow, Wastes space

* OrderedDict: New programmers aren't tripped up. Faster, smaller.

* Hypothetical UnorderedDict: Confuses new programmers again. Maybe even faster, if anybody builds it, which no-one volunteered to do.

Choosing OrderedDict was a no brainer for a language like Python.

You can't beat say Swiss Tables (a modern C++ unordered map with excellent performance) with the approach taken in OrderedDict not because we just don't know some optimisation, but because Swiss Tables is doing something a lot faster than what Python does today.

Swiss Tables is SIMD. In a single CPU instruction it can examine an entire cacheline of RAM to see if it matches your key (suggesting your value is probably in one of those slots) and in the process identify cases where any slots are empty and yet your key matched nothing, meaning it can stop looking because your key wasn't in this map at all.

This requires a very low-level understanding of how the CPU and RAM hierarchy works, and also knowledge of how to use SIMD instructions to get right, but that's fine the Swiss Tables team had those things and needed that performance. To make it fly though, you can't preserve order, the information needed isn't stored anywhere and storing it would make it slower and bigger.