13 ms·
That does look pretty nice for this example. I think the problem with it is that introduces too much new syntax that you have to memorize. The beauty of a for l
by rand_r 5y ago
That does look pretty nice for this example. I think the problem with it is that introduces too much new syntax that you have to memorize. The beauty of a for loop is that you can do _anything_ with it. And it all works with the same syntax.
for item in array:
item.foo = bar
for item in array:
item.foo = item.foo * 2
for item in array:
my_bar_func(item.foo)
If you special case certain uses of a for loop and add language syntax around it, of course you can make code terser. But it's nice to rely on a small set of very generally useful syntax.
- pasquinelli 5y agodepends on how many different types of loops there really are. now _that_ would make an interesting article.
- dragonwriter 5y ago> The beauty of a for loop is that you can do _anything_ with it. That’s also the curse: a generic loop can be almost anything (looping over an iterable can't quite express anything, but it can do a lot), so seeing it tells you nothing. C-style loops can do more (literally anything), and loop-over-iterable syntax has been generally preferred where it can be applied because it tells you more (even if only a little more) about what the block of code is doing up-front. Constructs that are more specific than loop-over-iterable can be correspondingly more expressive.