How I learned to stop worrying and love JavaScript

by jasonsouthern on 2010/02/13

[Scene: A Structural Programming Anonymous meeting]

Protagonist: My name is Jason and I’m a recovering classical inheritance OO programmer. I’m mostly speak Java, but I’ve dabbled in other OO languages such as C# and Objective-C. I have unabashedly promoted the virtues of strong typing: compile-time safety, invariant types, re-use. You get the picture.

Attendees (in unison monotone voice): Hello, Jason.

[End Scene]

I now realize that my disgust for unreadable, unmaintainable code (a.k.a. “spaghetti code”) pushed me to espouse strong typing over weak typing. I must confess, I forgot the axiom: anything can be abused.

But this post isn’t so much about my past as it is about my change in perception of loosely typed languages like JavaScript. I first learned JavaScript in 1997. I was motivated to do so because I wanted to animate navigation menus and I was working a  job where we looked trade the power and arcaneness of Perl for LiveScript on Netscape Enterprise Server. All of this was before I had immersed myself in OO or Java. The lack of tools made the language feel clumsy and awkward. I never felt as productive in JavaScript as I felt writing in other scripting languages at the time: Perl, VBScript, CFML.

Fast forward to today. I’ve spent the last 10 years primarily doing OOP with Java. The use of JavaScript has proliferated. Nearly every web application I use daily runs JavaScript. The biggest internet companies like Google and Yahoo are highly invested in it. Numerous libraries exist: Dojo, Ext JS, jQuery, Scriptulous, etc. These same companies and others commit to these libraries. JavaScript is now so widely used that some claim it may be the world’s most popular programming language or the world’s must successful scripting language. While there may not be enough evidence to either prove or dispute these claims, there is no denying JavaScript’s importance in the growth of the web and its position at the center of RIA.

After becoming a TweetDeck user, my eyes opened to the use of JavaScript outside of the browser. TweetDeck is an AIR application. AIR, Adobe Integrated Runtime, is Adobe’s attempt to take over cross-platform desktop applications by leveraging web technologies like HTML, JavaScript and AJAX. Sure you can write desktop applications using Java or .NET, but there is a whole community of programmers who have cut their teeth with web technologies. Why not build thicker client applications using the web holy trinity of  JavaScript, HTML and AJAX?

I’ve now spent the last couple of weeks re-introducing myself to JavaScript. I’ve read a couple of books, started building AIR applications using the Aptana Studio plug-in for Eclipse, watched many of Douglas Crockford’s JavaScript videos available on Yahoo. This exploration has made me realize maybe the reason I didn’t like JavaScript was that I didn’t grasp the inheritance model. Much to my delight, all the things I know and love about encapsulation and inheritance are present in JavaScript. While there isn’t classical polymorphism in JavaScript (because it’s a loosely typed language, duh), I am finding that I can do with out it.

I am reminded that one of the key aspects of any engineering discipline is choosing the right tool for the job. Being able to program effectively in JavaScript is a key skill. There are merits and drawbacks to both strong and weak typed languages. Knowing when and how to use them is the key.

A weakly typed language is no more conducive to the production of spaghetti code. Spaghetti code can be as easily produced in a strongly typed language. Judgment and pragmatic programming principles protect code from chaos.

{ 1 trackback }

Jason Southern
2010/02/14 at 1:52 am

{ 1 comment… read it below or add one }

Suresh Punuru 2010/03/12 at 11:22 pm

Jason!. Good that you mentioned about pragmatic programming. I just ordered a copy of the book from eBay. I really liked the table of contents and TIPS at http://www.pragprog.com/the-pragmatic-programmer/extracts/tips

Reply

Leave a Comment

Previous post:

Next post: