3 ms·
Yes, loops, just like we learned in CS101.
by NateDad 12y ago
Yes, loops, just like we learned in CS101.
- wtf_is_up 12y agoBut writing a loop takes up at least 3 lines in my editor!
- frowaway001 12y agoI used to play with a small plastic hammer when I was in kindergarden thirty years ago! I will be very irritated if people laugh at me for trying to build my new house with this hammer now. -- Golangers
- gnuvince 12y agoLoops are basically just compares + labels + jumps, yet we abstracted away from those, because we saw that it was common to want to execute a block of code a given number of times (for loop) or as long as a condition held (while and do/while loops). In recent years, more languages (C++, Java) have added a construct for doing an operation on every element of a collection (for each). Why then can't we have more abstractions of patterns programmers write over and over again? It makes a lot of sense to have an operation to apply a function to every element of a collection (map) or to remove elements of a collection based on a predicate function (filter). Saying that we can write those with loops is the same as saying we can write loop with jumps: true, but have a specialized construct makes the intent of the programmer a lot more clear.