Rainforest

Sankuru

Implementing, customizing, extending, and troubleshooting Joomla/Virtuemart

Views: 935
SocialTwist Tell-a-Friend

Machine translation

English Arabic Chinese (Simplified) German Japanese Russian Spanish



Re-use open source

What you need, often exists already, and covers your requirements for 80%. We will add the remaining 20% for you.
The importance of first class functions PDF Print E-mail
User Rating: / 0
PoorBest 
Written by erik   
Wednesday, 11 November 2009 17:21

In a previous blog post, I introduced the distinction between monomorphic and polymorphic function calls:

monomorphic: typen+1=f(type1,type2,...,typen)

polymorphic: object=(find_function(f,object)) (object,object,...,object)

Any non-object oriented language can introduce object-oriented polymorphism, if its functions can return functions. In other words, implementing polymorphism with monomorphic functions requires the availability of higher-order functions or preferably first class functions. As you can see, the find_function function must return a function:

g=find_function(f,object)

In their underlying implementations, Java and C# obviously use first class functions, but do not give their users the ability to use them too. There are simply no first class functions available in Java or C#.

The absence of first-class functions, complicates source code to no end. For example, in order to responding to a button click, one already needs first class functions. An example in javascript with a first class function:

function f() { alert("hello"); }
button.onClick=f;

 

You can express something similar in C.

You will not get away with something simple like this, however, in Java. There are no first-class functions in Java, even though Java itself is implemented using them.

Look at how complex things become when doing something as simple as handling a button click in Java:

aButton.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("Hello There");
}
});

 

In response, the java crowd will undoubtedly produce their well-known excusezilla: Java source code needs to be more complicated, because that is what it requires for things to be "enterprise grade".

Of course, this is just an excuse trying to gloss over the inherent inferiority of the Java language. The fragment of Java code listed above, is overly complicated, for no other reason than the fact that Java does not support first class functions. C# does not support first class functions either. In C#, the problem is solved with yet another verbose and non-sensical approach involving "delegates".

 

Conclusion

Both C and Javascript, with their relatively simple grammars, support first-class functions, while Java and C# don't.

As I argued in a previous post, the massive efforts and additional complexity invested in static typing, as practiced in Java and C#, do not yield any commesurate payoff. It is simply a waste of time.

Therefore, the use of Java or C# for any serious application will simply flush more software development budget dollars down the drain, for inferior results.

 


blog comments powered by Disqus
 
 
Joomla 1.5 Templates by Joomlashack