No, the thing that stopped Java having function composition was the lack of (ergonomic) closures. But it got closures in 2014, and now you can do function composition. Despite the fact that it still doesn't have top-level functions.
I still don't really understand where all the XML came from, or the wave of equally unnecessary annotation-based dependency injection that came afterwards. There has been a dream of "write reusable components, then compose them to form applications" that has been very strong in Java right from the outset, and i tentatively think that people just didn't get that you could do the composition in code.
Yeah, Java does that to people. It's such a limited language that it becomes impossible to conceive of better ways to solve problems.
Apparently it's come a long way since Java 6, it's even broken backwards compatibility, never expected that to happen. It's adopted many functional concepts in the usual insanely verbose Java style. Still a very limited language though, especially when compared to real functional and object-oriented languages. It's limited even when compared to C.
https://news.ycombinator.com/item?id=16143918
> The key point here is our programmers are Googlers, they’re not researchers.
> They’re not capable of understanding a brilliant language
> So, the language that we give them has to be easy for them to understand
It's pretty insulting in my opinion. Imagine being a programmer at Google, likely one of the best jobs in tech, and reading this.
Now you can have lambdas, and they go to a generated class as methods, so that the JVM could execute them.
Where XML came from: how do you configure WebSphere in 2000? XML was all the rage since mid-1990s. It had a ton of advantages, back when you did not have JSON, YAML, or TOML.
Even if you have static methods, you still need to use this stuff because they are methods, not functions. Classes aren't objects so they can't implement interfaces or be passed around as parameters. Gotta make things like singletons and factories because of this just so you can essentially pass a function pointer around. There's names for stuff that in better languages just happens naturally without people even thinking about it.
Why do you think the Gang of Four book uses Smalltalk and C++ without any traces from Java?
… perhaps came later, with embellishment
DI allows a generic runtime to instantiate and compose component graphs [via declarative initialization contexts]. The idea was we'd have reusable components. Somewhere along the line came Spring ("J2EE is too complex" lol) and before you knew it, any old application was using DI and now (per a scan of comments in this thread) everyone is quite confused what is the purpose of "passing variables to your functions" in this obscure manner.
> NEO was re-positioned as a Java system with the introduction of the "Joe" framework,[2] but it saw little use. Components of NEO and Joe were eventually subsumed into Enterprise JavaBeans
https://en.m.wikipedia.org/wiki/Distributed_Objects_Everywhe...
And we did just the same with objects factories and directories on the listed technologies.
Perhaps "What people like to blame Java for…" is how it was required to be done in Java.
Perhaps Java became a victim of enterprise culture, just like nowadays everyone is doing system level DI with Kubernetes orchestrations and WebAPI?
When those are the appropriate search keywords.
But, unlike Java, Smalltalk is (utterly) dynamic, and you don't have to declare a class for your code block. In Java, you had to dance that dance, until lambdas were introduced to let the compiler do that for you.
"Every object in Smalltalk, even a lowly integer, has a set of messages, a protocol, that defines the explicit communication to which that object can respond. Internally, objects may have local storage and access to other shared information which comprise the implicit context of all communication."
p290 Byte Magazine 1981
http://worrydream.com/refs/Ingalls%20-%20Design%20Principles...
> > > … instead of a function…
Instead of a function, a message.
Let's take that literally —
perform: aSymbol with: anObject
Answer the result of sending a binary message
to the receiver with selector aSymbol and argument
anObject. Report an error if the number of arguments
expected by the selector is not one.
(For more of those methods, see p425https://rmod-files.lille.inria.fr/FreeBooks/SmalltalkVTutori... )
Last-time I remember using those #perform methods, it was for testing — walking the code sending arbitrary messages and and arguments.
"Smalltalk blocks and closures origin and evolution" Juan Escalada
And no lambdas are not implemented that way, rather they take advantage of invokedynamic.
"Design Patterns: Elements of Reusable Object-Oriented Software"
You forgot to check the publishing date,
https://en.wikipedia.org/wiki/Design_Patterns
Publication date => 1994
https://en.wikipedia.org/wiki/Java_(programming_language)
First public release => 1995
No I did not.
You don't. I do.
The authors’ statement is clear.
Java does support lambda expressions.
Also, the fact that in Java everything is a class is something that cuts both ways. As you're already going to have classes, you can have your pure functions as static member functions from any class that suits your fancy. That pretty much works as a function within a namespace.
The problem of the static method as a function is not the implementation, it's the ergonomics. It's not terrible, but certainly it is wordy. I agree that a conservative approach to adding any new syntax is wise for a project of such an industry footprint. But the wordiness is what the original article points at, not any logical design faults.
I wonder if such contracts are are solved now like in other languages with typed function references/pointers - C++/Go/etc (syntactic sugar is enough, doesn't have to be variadic generics). I remember 'var' was introduced so I suppose that worked if the closure type could be inferred.
I would take that over Go's special syntax for map any day as I now have the power to create my own functional interfaces and plug them into Java's standard library.
The final is to avoid some mistakes, but they are still effectively closures.
You can pass static methods as parameters in at least C++, Python and Javascript.
Hence you can't have function composition, instead you get dependency injection, with an extra layer of XML files in most frameworks to allow injecting different stuff without recompiling the classes without access to the source, or just obviating the need to recompile.
DI is a nice concept, and is used to solve a real problem of declaratively configuring closed-source code. I bet that declarative DI implemented for CL or Scheme would look more compact and neat than the typical Java approach.