3 ms·
Really weird to read this and not a single mention (in the article or ITT) of the most critical concept here: Composability. That is what ranges can do for your
by Quekid5 8y ago
Really weird to read this and not a single mention (in the article or ITT) of the most critical concept here: Composability. That is what ranges can do for your code -- make it composable.
The imperative-style examples don't compose in any meaningful sense. The only thing you can really do with the imperative style programs is to sequence them, i.e. run one after the other.
With ranges you can apply various types of transformations, combine multiple ranges, it lets the consumer(!) decide how much work should be done, etc. etc.
The gives incredible leverage for code reuse.
- notacoward 8y ago> The only thing you can really do with the imperative style programs is to sequence them What's wrong with that? Isn't that the most readily accessible (and therefore maintainable) kind of composition? I realize that some people might prefer other forms of transformation or combination, but can you give an example of where it provides a tangible (not just aesthetic) benefit?
- Quekid5 8y agoI answered that in the following paragraphs: It gives you a huge amount of potential for reuse -- essentially for free. (Alright, this is C++ so there's a little bit of cost due to a tiny amount of extra 'syntax' where C++ imperative syntax is "free", but that's trivial for any but the most trivial of examples.)
- notacoward 8y ago"Following paragraphs" is an ambitious term for barely one line of text. You have claimed there is some unspecified promised land of reuse through unspecified transformations and combinations, but you really haven't shown anything that's not equally achievable with "mere" sequential application. It still looks like a matter of aesthetics - that you prefer a more syntax-laden functional style, but not one that's objectively better.
- avmich 8y agoLet's define "objectively better" as "allowing to do A, then B as well as to do B, then A - rather than only allowing to do A, then B". Then composability - defined as "allowing to do A, then B as well as to do B, then A" - is objectively better than imperative style - defined as "only allowing to do A, then B". In these terms it looks like a tautology. But the essense is still there - if for some reason you'd like to have a freedom of order of some transformations, you need composability, as an opposite to an approach which prescribes the order.