8 ms·
There are many common operations in programming, and it's worthwhile building a consistent syntax for them. Over time, as one layer of abstraction solidifies it
by porlw 12y ago
There are many common operations in programming, and it's worthwhile building a consistent syntax for them. Over time, as one layer of abstraction solidifies it's possible to see common patterns at the next level up.
It saves brainpower because you you don't need to analyse the logic within the structure to understand what the operation is intended to produce.
E.g. in the old days:
10 I=1
20 PRINT A[I]
30 I=I+1
40 IF I <= 10 THEN GOTO 20
You need to parse the logic to realise "Ah, this is a for loop". The I variable and the IF statement are bookkeeping code that doesn't have any relevance to the actual effect you're trying to produce.
This construct is common enough that the for-loop was developed. Likewise with the if/else construct and others.
The old fogeys would say "we don't need this structured programming nonsense, gotos are more flexible. I can easily look at this and understand what's going on".
Structured programming is now widespread enough that we don't think of it as anything special, it's just part of "programming" in general.
Now there are several common operations that we do when looping over a list of items. Things like maps, folds and gathers are just building another level on top of structured programming, hiding the bookkeeping code and making similar operation similar, so you can concentrate on the unique aspects of the program.