Thursday, May 14, 2009

Java is like classical, Javascript is like jazz

I've been looking at Javascript in more detail as part of a side project I'm working on.  I've been reading Javascript code and feeling my head hurt, and it took a while for me to figure out what was causing the dissonance.

I've been a Java programmer for years.  I have always enjoyed its clarity and structure.  The static typing lets you say what you mean and mean what you say. 

Reading Javascript code isn't like that.  Nobody tells you what somethings going to be used for, and it can change over time.  Objects can be of any type and can have any number of elements.  Functions are created and destroyed like wafts of smoke.

I finally realized the Javascript is like impressionistic and avant-garde art, like jazz.  It flows, it molds, it changes, like a dream.  Java is like renaissance art, like classical music.  Its beauty is in its form and structure, but it constrains your ability to express and invent - you have to follow the forms given to you.

Of course this isn't a perfect match, but it helped me remove my Classical hat and put on my Jazz hat when dealing with Javascript.  And it also helped me understand why Java is so popular in the enterprise, while Javascript (and other dynamic languages) are so popular for the creative types building consumer-facing applications.

Sometimes a little metaphor like that can go a long way.  Now all I need to do is start wearing black and pierce my lip...


Neil's Dev Stuff said...

Know what you mean Dave.

Think object oriented though with javascript and it all falls into place, the script part in its name is the most off putting.

Once I had read Douglas Crockford's "Javascript The Good Parts" and did a fair amount of work in EXTJS it all fell into place.

Dont forget to use JSLINT to verify your js code. It just saves one hell of a lot of time debugging.



Dominique De Vito said...

Very nice metaphor. Sounds accurate.

Rafał said...

JavaScript is to Java like Smooth Jazz to Jazz ;)

Thomas Fuchs said...

That is just beautiful.