1. 36
  1.  

  2. 19

    Holy crap that’s long.

    1. 12
      1. 4

        The technical blog post as a Socratic dialogue.

        1. 1

          especially with a step-by-step dialogue of what you’d normally go through when trying to tackle these issues

      2. 4

        I’m guessing you’re not using Mobile Safari, or else it would’ve already crashed.

        I am, it didn’t.

        1. 4

          In most (all?) programming languages specifying a type also implies choosing a particular layout in memory. That’s a pragmatic choice. But they could be separate concerns [1], but that would have an impact on source code readability (at least for as long as source code is plain text).

          [1] Check out https://www.janestreet.com/tech-talks/unboxed-types-for-ocaml/ to get an impression how these can be separate concerns.

          1. 10

            But they could be separate concerns [1], but that would have an impact on source code readability (at least for as long as source code is plain text).

            Could you describe this in more details? Ada lets you specify type and representation separately in a fairly readable manner in my opinion:

            -- Create a type Small on two bits where -7 is represented as 0b00, -6 as 0b01...
            type Small is range -7 .. -4 with Size => 2;
            
            -- Create a array type of 8 Booleans, packing it into a single byte
            type Arr is array (1 .. 8) of Boolean;
            pragma Pack (Arr);
            
            -- Create a struct where the fields span arbitrary ranges of bits
            type MyRec is record
              A : Boolean;
              B : Integer;
              C : Integer;
            end record;
            for MyRec use record
               A at 0 range 00 .. 04;
               B at 0 range 05 .. 37;
               C at 0 range 38 .. 128;
            end record;
            
            1. 5

              Wow, that is really elegant. Somehow I missed that Ada could do that. Rust could learn a lot from that level of clarity IMO. Thank you for this example!

            2. 3

              Rust actually has a bit of flexibility there. Not a huge amount, and less than the compiler actually uses in a practical sense, but some. Notable examples: References to small structures passed to a function may pass the function a pointer, or more likely will just copy the structure into registers and copy it back afterwards. Struct fields do not have any set order, so the compiler will reorder structs to squish out unnecessary padding. There’s not even any promise that two instances of the same struct will have the same representation, as far as I know. And of course, Option<NonNull<T>> may decide to use a null pointer to represent the None variant of the option.

              On the other hand, contrast Rust with the very first line of your link: “OCaml has a well-deserved reputation for compiling quickly…” :-P (Also wow that’s an excellent talk.)

            3. 1

              This is painfully close to my experience with learning rust. Although starting without async/await was harder, I’d say it gave me a better understanding of what exactly happens underneath the surface.