3 ms·
Here's my understanding: to get higher-order function calls to compile to fast code, you need some kind of compile-time code expansion: templates in C++, specia
by creata 5y ago
Here's my understanding: to get higher-order function calls to compile to fast code, you need some kind of compile-time code expansion: templates in C++, specialization in Haskell, monomorphization in Rust, etc. But if you make it too easy to have code expand into multiple instances, then you lose the fast compile times that Go's famous for, and that's a hard balance to strike.
- the-smug-one 5y agoGiven a call map(a, f) and a loop for _,e := range a { f(e); } both ought to have the same code size. Yes, map(a, f) will need to be inlined, but the for-loop is already inlined.
- creata 5y agoYou're right. To be clearer, the emphasis was on making it too easy to specialize: people don't just stop at maps and filters, they specialize everything, and that can have a significant impact on compilation times. For example, in Rust, people write stuff like [0] for the tiniest bit of syntax sugar, and they often don't bother extract out the non-generic part. [0]: https://news.ycombinator.com/item?id=24088407 https://news.ycombinator.com/item?id=24088407
- ben0x539 5y agoThe current idiomatic go style is to write your own for-loops for everything. Isn't that just manual specialization executed by the programmer rather than the compiler?