4 ms·
Swift even does this officially: ALL lambdas are called closures, even though there's nothing being closed over. Similarly, people refer to constructor functio
by nailer 11y ago
Swift even does this officially: ALL lambdas are called closures, even though there's nothing being closed over.
Similarly, people refer to constructor functions that always return objects of the same class/prototype as factories, despite both the GoF patterns that popularised the term showing dynamic output. IIRC Angular JS misuses the term this way too.
AFAICT it's either genuine ignorance of how/why these words describe or some kind of weird demonstration of cleverness by using a particular term, regardless of whether it's applicable or not.
- Ono-Sendai 11y agoIt's probably because, in an implementation of a staticly typed language, you have to treat all functions being passed around as closures. E.g. the type of a lambda expression needs to be one thing, and that is a closure. Whether or not any variables are actually closed over is irrelevant.
- nailer 11y agoCouldn't the type of a passed around function simply be 'function'? Why does it have to be inaccurate?
- Ono-Sendai 11y agoWell a function may in general have closed over arguments. Therefore it needs to be a closure. (If you have lexical scoping that is)