1. 22

  2. 2
    • APIs that return dicts don’t make any guarantees on how the keys are sorted, now they accidentally do. If I refactor code that changes the order keys are inserted, I may break code that does rely on ordering. You used to be able to detect such bugs because of hash randomization, but now that doesn’t have any effect on the key iteration order anymore, obviously.
    • There are two kinds of parameters: Positional ones and by-keyword. Since dict is now ordered, you have a new one: By position and by keyword. I don’t expect that a respectable API designer would rely on the order of keyword arguments, but now Python makes it possible.
    1. 1

      Because somebody outside of lobste.rs asked for an example for 2. and I can’t edit my comment anymore:

      Assume the following code:

      def foo(**kwargs):

      With Python <3.6 there is basically no guarantee in which order your keyword arguments are printed. If I call foo(a=1, b=2), the program may print ab or ba. On my machine I get the same output for foo(a=1, b=2) and foo(b=2, a=1). This is how it’s worked since whenever.

      WIth Python 3.6, the order is guaranteed: foo(a=1, b=2) appears to always print ab and foo(b=2, a=1) always ba. I’m not sure if this was intended.

    2. 2

      Does anyone know if a dictionary implemented in a low-level language like Rust/C/C++/D/Go, and using the same compact/ordered structure, would have the same benefits?

      1. 3

        It seems likely. Most of the benefits discussed in the pypy blogpost about it don’t have anything to do with Python (GC friendliness is the only one that does, and that would probably also affect Go and D depending on the details of their GC).

        1. 6

          Interesting. FWIW, Go intentionally “randomises” map iteration order (this was introduced after people started relying on a stable iteration order).

            1. 7

              Users are the worst.

        2. 1

          That would be exciting, and there is precedent for this. Timsort was developed for Python, and has found adoption elsewhere. It’s now the default sort for Java 7!

          1. 2