You can separate the function from the function execution environment when clients invoke it through a delegate (as in Command)?
You could collect them into a Collection and queue them too?
Functional composition becomes easier and more intuitive to implement?
From speaking to people who have studied in fields that required a lot of math, and now develop software for a living, first class functions are gaining traction because syntactically they are closer to how mathematicians work. Yes, it is really a short hand way of creating an anonymous class. However, from the usability POV, the differrence is analogous to difference between doing this
Both option are exactly the same from a programming POV. However, the second option is cleaner to read, and more importantly, makes sense for your target audience. It takes focus off the language.
Taking simple algebriac examples, when a mathemtician says
The variable x can be a constant, a value, or a function. Mathematically, it doesn't make a differrence that x = 2, or x = m or x = f(m). Right now, in Java, there is a remarkable differrence in syntax when you want to support the third option, and having to support all 3 options makes the code harder to read
Right now, in Java, there is a remarkable differrence in syntax when you want to support the third option, and having to support all 3 options makes the code harder to read
In this context, the concept of something being "harder" is subjective. What some individuals might find difficult, others might find very easy. Each human brain is different and human intellect varies. Certain individuals may apply a notion of mathematical correctness to a creative activity such as business software engineering and find themselves lost when challenged with something cloudy, unknown or hypothetical.
If a function is a first class object, you can treat it like any other object so you can pass them around or create them on the fly, as with lambdas/closures in Python/Groovy etc, which also helps to give dynamic languages their flexibility and syntactic sugar. Even as a dumb grunt programmer, this seems much more intuitive to my limited intellect than a lot of messing about with halfway house solutions like "inner classes" whose sole purpose is to give you access to a method (function) call. Another advantage claimed for the functional approach in general is the lack of side effects i.e. the idea is that a function always produces the same results for the same input and does not accidentally affect other data.
Just thought of this. First class functions in Java might also make Proxying simpler.. and actually might eliminate the need for java.lang.Proxy, which IMO is a bit clunky. You could implement a generic interceptor function that takes the intercepted function as a parameter and returns a function that has the code weaved in. For example, you could have
Yeah the interceptor code is hard to read if you are not familiar with the syntax, but train yourself to understand it and it's way simpler than creating Proxy