3 ms·
In your g(f(x)) composition example you said that g would be filtering out eveery other record, that could only make thiings faster, not slower. Could you form
by jose_zap 6y ago
In your g(f(x)) composition example you said that g would be filtering out eveery other record, that could only make thiings faster, not slower.
Could you formulate an example where the composition would be asymptotically slower only for lazy languages?
As I said before, laziness is actually an optimization strategy. If anything, it can only make the composition faster than it would be in a strict language (although rarely so)
- lmm 6y ago> Could you formulate an example where the composition would be asymptotically slower only for lazy languages? No; we both know no such thing exists. The same code will always be asymptotically faster in a lazy language. The problem is that lazy languages (or at least, the one lazy language in widespread use) encourage a style of code that would be asymptotically slower if written in a strict language. In a strict language, a function is slow or fast, and a slow function is always a problem - which means performance is easy to reason about. In a lazy language, a slow function is not necessarily a problem, depending on how it's used, and so you can't understand performance without understanding the whole program. An unreliable optimisation can be worse than no optimisation at all. Worst practices should be hard. In theory an extremely vigilant development team could always write code that would be fast if executed strictly, and therefore guarantee no performance problems, but this would require an enormous manual effort since the language doesn't help you with it at all.