6 ms·
Just write the loop. It's 3 lines.
by NateDad 12y ago
Just write the loop. It's 3 lines.
- Touche 12y agoI can't compose loops.
- NateDad 12y agoIt sounds like you're trying to stuff too much in a single line. Line returns aren't in short supply. You can just write the loop and then write another loop. It'll be more clear that way anyway. And if you really do this a lot, write a nicely named helper function. That will also make your code more clear.
- Argorak 12y agoComposition is not about writing everything in one line.
- NateDad 12y agoYou'll have to explain to me what you mean by composition if you don't mean foo(bar(baz())) or foo().bar().baz() Composition means putting things together, if you're not doing it on one line, then what's wrong with a loop?
- Argorak 12y agoFor example, Iterators are composable. I can return one from a function, append another iterator to the chain, return that and then iterate over the whole result (possibly, this leads to only one iteration internally). I cannot return a loop.
- cpeterso 12y agoThe helper function is called "map".
- Daishiman 12y agoIt's not clear; you suddenly have to read 5 times more code, your code no longer makes intent clear. You now have to understand the intent of multiple loops and make sure you're not introducing subtle bugs. I cannot see a single way in which that is objectively "better".
- NateDad 12y agoMore code does not mean less clear. I've seen some really hairy list comprehensions that I broke out into 3 loops and made them 1000x more clear, because you could actually follow what each conversion was doing.
- AnimalMuppet 12y agoThe problem Go is trying to solve is that of programming at scale (say, a ten-million-line code base that will survive for two decades). The problem it is trying to solve is not how to make it easier to write very small parts of the program. These two are not the same problem. (Problems of scale are not the same problems but more of them. They are different problems.) Does the functional style of maps and composition cause problems at scale? I don't have any data. However, I would not begin by assuming that Go's designers were either stupid or ignorant of functional programming idioms.
- deleted 12y ago[deleted]