On Fri, Jun 11, 2021 at 7:47 AM Jelle Zijlstra email@example.com wrote:
El jue, 10 jun 2021 a las 19:30, Cameron Simpson (firstname.lastname@example.org) escribió:
On 11Jun2021 10:01, Cameron Simpson email@example.com wrote:
It also struck me: functions with _no_ parameters are pretty rare.
I got curious so I checked a large codebase I have access to. Out of 85540 functions, 8244 take no arguments. Many of them are test functions.
I'm sure the idea is dead now, but it reminds me of an amusing anecdote I heard in college.
You may not have heard of a language named Algol-68, but it was a big thing when I learned programming in Amsterdam in the late '70s. Like its predecessor, Algol-60, it had a feature where parameter-less functions could both be *defined* and *called* without parentheses.
Now, in Algol-60, this was easy, because there were no function pointers, so whenever the compiler saw the name of a parameter-less function, it would generate the code to call it. (Example: "x := random*2".) But Algol-68 *did* have function pointers, so the language design committee had to introduce a complicated wrinkle into the type system so that you could write things like "f := random" (interpreting it as a function pointer) but also "x := 2*random" (calling it). The distinguishing property was the type of the receiving end (i.e., f had to be declared as a parameterless function pointer, and x had to be a number).
So one of the classes I took near the end of my studies was taught by the lead author of Algol-68 (Adriaan van Wijngaarden). He was well respected and near retirement age, so he could do what he wanted in class, and sometimes he just told anecdotes from the past (I'd love such a job :-). One day the issue with parameter-less functions came up, and by then a new language named C had gained some notoriety. C, of course, has function pointers and parameter-less functions, but both the declaration and the call must use an empty pair of parentheses (i.e, "x = 2*random()", like Python). Van Wijngaarden told us, somewhat ruefully, that, had the design committee known that programmers would be happy to write that empty pair of parentheses, they would have been able to simplify a significant corner of Algol-68's type system.
This was one of the seminal ideas that went into Python's design.