2 ms·
Tl;dr : APL has implicit loops because almost everything is an array, and mentioning an array implies a loop to process it. In C++, nowadays, people are encour
by ncmncm 7y ago
Tl;dr : APL has implicit loops because almost everything is an array, and mentioning an array implies a loop to process it.
In C++, nowadays, people are encouraged to use Standard Library algorithms in preference to most loops; and to make an algorithm out of any loop that can't be cleanly replaced with a Standard one, and call that. The reasoning is similar to that explained in the article, except that saying which you are doing, by naming the algorithm, communicates better what you are trying to achieve than does coding the loop in place.
In APL, of course, naming anything with more than two or three letters, or wrapping a one- or two-operator expression in a function, gets you looked at funny, so that reason wouldn't apply.
- 7thaccount 7y agoFrom what I've read, your last paragraph is true, but only because the naming often isn't necessary. The importance of abstraction in a codebase that is 60 pages of code is high, but it fades away if the equivalent J program can be 5 pages of expressions. Instead of defining some numerical operation that is only 5 characters long, just use the 5 characters in the 2 to 3 places where it is needed in your 5 pages of code. This way everything is explicit and you don't have to reference back to the definition. This would be an awful idea in Java, but it works great in J and APL. Aaron Hsu talks about this with his parallel APL compiler and refers to this as working at the macro level. Note that he has plenty of named items that are passed around in a data flow fashion, but he doesn't need to name every little function.
- ncmncm 7y agoThe naming is never necessary, in any language. Even where a function is called, the name may be uninformative. A name is an opportunity to provide useful information about intent to the reader. Open-coding, however concise it may be, fails to communicate intent.