4 ms·
closures predate both languages and have a lot of contemporaneous examples, so I don't think that fits.
by ska 7y ago
closures predate both languages and have a lot of contemporaneous examples, so I don't think that fits.
- AnimalMuppet 7y agoI know. But I think Java had them before C++, and I think that Java was the first mainstream, C++-syntax, object-oriented language to have them. (Yeah, I know, that's not saying much, because C++ and Java are the only two mainstream, C++-syntax, object-oriented languages.) The point was, C++ could have looked at Java as proof that a language like C++ could have closures, and so one could suspect that the immediate, direct inspiration was from Java. I only mentioned closures because it's the only feature I could think of that C++ has, but Java had first. (I welcome other examples, if anyone has them.)
- ska 7y agoI think this line of logic risks a "no true scotsman" issue, but a bunch of languages supported them before Java. I have no idea what the c++ committee were using as predicates, mind you, might have been java inspired.
- AnimalMuppet 7y ago> I have no idea what the c++ committee were using as predicates And in fairness, neither do I. My point wasn't "C++ copied closures from Java". My point was "I can't think of anything else they copied from Java", and therefore that I suspected that the answer to jedberg's question was no.
- gpderetta 7y agoThe c++11 memory model is explicitly an evolution of Java memory model. There is an effort to get checked exceptions in the language. I can't think of anything else.
- int_19h 7y agoC# was the first mainstream language with a C-style syntax to have them - anonymous delegates in C# 2 (2005), then lambdas with type inference in C# 4 (2010). Java got them in Java 7 in 2011, more or less at the same time as C++11 did. In any case, Java and C# closures weren't particularly helpful to C++, because they have only shown that a garbage-collected language can have them - the main complexity around closures is wrt memory management and ownership. Hence why C++ closures are very different from either Java or C#. I suspect that C++ got the now-deprecated exception specifiers - throw() on functions - from Java. But not entirely sure.
- gpderetta 7y agoGCC has had closures in C in the form of nested functions for as long as I can remember(but only as downward funargs).
- saagarjha 7y agoAnd the implementation was always an outright catastrophe…
- int_19h 7y agoI'm not sure these qualify as closures. But if they do, then they've been around in that exact form (named local functions with language semantics preventing them from outliving their environment) since Algol-60.
- gpderetta 7y agoI guess you are right, a true closure need to be able to outlive the scope of the variables it is closing over. Anyway, I wasn't making any claim that C got them first, far from it.
- fanf2 7y agoI checked my copy of the C++ Programming Language (2nd edition, 1991) which has throw() exception specifiers on functions. The Java project started in 1991.