[PRL] Of course our programming language can do this

Doug Orleans dougorleans at gmail.com
Wed Aug 2 13:11:02 EDT 2006


 > Object-oriented programming languages aren't completely convinced that you
 > should be allowed to do anything with functions.
 > 
 > Java required you to create a whole object with a single method called a
 > functor if you wanted to treat a function like a first class
 > object.

I just realized another bit of irony about this post: his examples are
written in ECMAScript, which is, of course, an object-oriented
programming language.  In particular,

       function(x) { alert("pot " + x); }  );

is basically just syntactic sugar for

       new Function("x", "alert(\"pot \" + x);");

which results in an object whose [[Call]] method will execute that
alert statement.  (And "foo(bar)" is syntactic sugar for "execute the
[[Call]] method of object foo with argument bar".)  So it seems like
the main reason ECMAScript wins over Java (by Spolsky's measure) is
that it has this syntactic sugar to make function expressions simpler.
Now if only Java had macros...  http://jse.sourceforge.net/

--dougorleans at gmail.com

P.S. Took me a while to find an HTML version of the ECMAScript spec,
but here it is:  http://bclary.com/2004/11/07/



More information about the PRL mailing list