Alastair Lockie

Nuggets of JavaScript

From Java to JavaScript

Firstly, hello and welcome to my blog. It’s been on my todo list to start this longer than ‘sort out the photos under the bed’, and that’s saying something. I’ve finally got round to starting it now for two reasons. Firstly, I recently read this excellent post outlining the benefits of blogging, such as improved clarity of thought and more effective communication. Secondly, I have started on a new stage of my career, and I want to share my thoughts and experiences.

My background

I’ve been a professional Java developer for five years now, and I’ve decided to take a bit of a gamble. I’m turning my back on the language and have accepted a job as a full-time JavaScript developer. To those that still view JavaScript as a toy language which isn’t for serious programmers, this may seem like a bit of a foolish life decision.

I must confess, if you’d asked me a couple of years ago I may well have thought the same. Even up until a few months ago I hadn’t seriously entertained the idea of giving up Java. Ignoring brief educational forays into Visual Basic, ActionScript and even ADA, Java is the first language I truly knew. From BlueJ at University through to Technical Lead on a suite of web apps in my previous company, I’d always thought of myself as a Java developer. I feel a real sense of flow when I’m flying through an inheritance hierarchy refactor, the NetBeans keyboard shortcuts burned into my finger muscle memory.

There is still a part of me that considers Java to be a ‘proper’ programming language compared to JavaScript. The challenges of multi-threading, the security of strong typing, and the maturity of frameworks such as Spring and Hibernate are not easy to turn one’s back on. Java is a very established and well-respected language, and I believe that despite the growth of languages such as Ruby and Python, it still has many years ahead of it.

The Ascendance of JavaScript

In contrast, although JavaScript first appeared in Netscape 2 way back in 1995, it wasn’t until the appearance of rich web applications like GMail and the proliferation of AJAX a decade later that people started to sit up and take notice.

For me, there were three main reasons why JavaScript is well worth considering as a primary language. Firstly, and most importantly, there is a more direct connection with the thing I’m creating. Coding with Java can be deeply rewarding, but you don’t really get to see very much. Aside from the green bars of passing tests, or the steady stream of logs in the console, positive feedback needs to come from the internal knowledge of a job well done. Coding in JavaScript, on the other hand, usually involves active changes to the DOM - changes that you can see and interact with, changes that feel more tangible somehow. I know that this is a personal preference, but for me this feedback is important.

The second aspect to JavaScript development that tempted me across is the rapid evolution of the language. Despite the appearance of new frameworks like Play, and new features to the language itself with version updates, Java felt quite slow moving to me. JavaScript, by contrast, is the top language on github (at the time of writing), and it shows. There seems to be a new testing framework or MV* framework cropping up each month, and that’s not to mention the lightning pace of Node.js’ evolution. The buzz of a language on the move is both exciting and addictive - go to any JavaScript conference and you’ll see what I mean.

Finally, there is the sheer ubiquity of the language. There is a JavaScript interpreter on almost every web-enabled device. What started out as a quick & dirty language knocked together by Brendan Eich in just 10 days has become the world’s most widely supported programming language. JavaScript might have it’s problems but I don’t see it going anywhere anytime soon.

jQuery - the gateway drug

Like many, my introduction into the pleasures of JavaScript came through the warm and friendly world of jQuery. There were other libraries before jQuery to aid with DOM manipulation (traditionally the most painful and inconsistent aspect of JavaScript development), but jQuery absolutely nailed it.

jQuery revolutionised front-end development for a great many people, but I think everybody who uses it heavily hits a point where they come to realise that learning the library alone and not the language just won’t cut it. This point came for me whilst I was devouring the excellent ‘jQuery in Action’, and read the Appendix which outlined some core JavaScript fundamentals such as closures and object literals. After countless recommendations, I got hold of a copy of Douglas Crockford’s JavaScript - the Good Parts. When I found myself choosing to spend a sunny afternoon sitting up on the Surrey Hills with a beer and said book, I realised that I was really starting to fall for this language.

My conversion came all the quicker thanks to the incredible community surrounding jQuery and JavaScript. I had barely used Twitter up until I read a blog post by @rem on how to recognise a poorly written jQuery plugin and decided to follow him; same story with Paul Irish’s now famous ‘10 things I learned from the jQuery source’ video. Pretty soon, I was following more and more JavaScript luminaries, and I finally discovered what people meant when they quote Twitter as a great resource for learning. I now follow over 300 people, and most of them are JavaScript developers.

I know that these views are not universally shared, and for me this shift of focus simply brings my day to day job more in line with my personal style of programming. For others, Java is a great choice, but for me it felt like programming in a treacle-filled strait jacket. I’m looking forward to a simpler, faster, and in my opinion more elegant life of programming.