[HN Gopher] An O(1) Generic Blog Post About Rust
       ___________________________________________________________________
        
       An O(1) Generic Blog Post About Rust
        
       Author : peterkos
       Score  : 18 points
       Date   : 2022-05-02 18:30 UTC (4 hours ago)
        
 (HTM) web link (peterkos.me)
 (TXT) w3m dump (peterkos.me)
        
       | NoraCodes wrote:
       | I appreciate the attention to the social and organizational
       | aspect of implementation here. Every piece of software has a
       | somewhat nonlinear curve in the difficulty of adding new features
       | as the codebase gets more complex, but it's especially bad in
       | compilers. Adding something as complex and all-pervasive as
       | dependent types - and this is dependent types, just in a Rusty
       | costume! - is, clearly, on another level. I'm very excited for a
       | more capable incarnation of this feature, but I'm not holding my
       | breath for its stabilization.
        
       | davidhyde wrote:
       | Great article! I would just like to add to the point about C#
       | generics.
       | 
       | > "generics in Rust are zero-cost abstractions. rustc performs a
       | process called monomorphization, where generic items (methods,
       | structs, etc.) are "flattened" at compile time into only the
       | types that are used. (Compare this to a language like C#, where
       | generics are evaluated at runtime.)"
       | 
       | I believe that generics are evaluated at runtime in C# due to
       | just-in-time compilation. C#'s implementation of generics (which
       | they call reification) is more similar to Rust's monomorphization
       | than, say Go and Java's lookup table type erasure approach.
       | 
       | More information about this can be found here:
       | https://stackoverflow.com/questions/31876372/what-is-reifica...
        
         | melony wrote:
         | What about the Dyn type parameter?
        
           | davidhyde wrote:
           | Good point! Using dyn Trait syntax (aka, dynamic dispatch)
           | uses type erasure and is kind-of like Go and Java's
           | implementation of Generics I guess. You can definitely use
           | that in Rust but the article is about impl Trait syntax which
           | is for concrete types (not type erased)
        
       | kzrdude wrote:
       | > And before that, in the pre-alpha days of Rust, arrays were
       | defined with a variadic macro. The /* something */ above was a
       | [T, ..$N], where T is the type, and ..$N defines a range (I
       | believe -- old Rust is weird) up to the number of specified
       | elements.
       | 
       | This is just a misunderstanding. The `..$N` was just the array
       | length syntax. Now the syntax is `[T; N]` with no change in
       | meaning - there was no variadic magic.
        
       ___________________________________________________________________
       (page generated 2022-05-02 23:01 UTC)