1. 57

  2. 5

    Slightly understates which language is using what solution, languages like D and C++ often use a whole bunch of those solutions in different places.

    D’s special sauce, the string mixin, sounds crude, but is surprisingly powerful when combined with compile time function evaluation and static if.

    Other languages like Rust need to provide an API into the the compilers understanding of the AST and types.

    D says there is an API and language that D programmers already know and understand. D. So at compile time your program can introspect as much as you need to generate the correct D and mix it in…. which can again introspect as much as it needs at compile time and all gets evaluated and folded out before run time.

    1. 2

      This is a nice overview. Swift’s solution sounds very interesting. Rust has a plenty of situations in which it can’t use a type, because it doesn’t know its size. Swift’s solution seems obvious — let the object say what size it has.

      1. 2

        Sounds kind of like RFC 1909.

      2. 2

        Great post about a complex topic!

        I think Swift “witness tables” could be a great fit for generics in Go (making possible to implement generics data structures without boxing and without monomorphization, by passing items type and size as parameters). That’s more or less how built-in generic data structures are already implemented (slices and maps).