3 ms·
I really like chaining array methods but you should also never forget it's incredibly easy to introduce crazy computational complexity with them.
by patates 5y ago
I really like chaining array methods but you should also never forget it's incredibly easy to introduce crazy computational complexity with them.
- coder543 5y agoRust has lazy iterators, so a chain of iterator steps like this has the same complexity as a single for loop over the iterator. There's no reason Go couldn't do that same thing.
- stouset 5y agoIn fact, Rust's version compiles down to pretty much the optimal looping form. It will even vectorize your iterations using SIMD.
- throwaway894345 5y agoRust is seriously cool in this regard, but Go aspires to be different, namely more C-like and less C++-like. This means a dumber, faster compiler that is easier to intuit about, for better or worse. Rust is such an amazing piece of engineering (moreso an amazing process and culture for producing an amazing language), but I think Go’s approach is right for a whole lot of software—lots of things don’t need to be insanely performant (lots of things are chugging along in Python, which runs 2-3 orders of magnitude slower than Go) but we do need to be able to iterate on them quickly in a development context involving dozens or hundreds of other people.
- jolux 5y agoNot if you have solid lazy iterator support in the language. If they’re strict and every link in the chain is adding O(n) to the complexity then yes, this is a problem.