Write More JavaScript and Write It Better

0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×

I’m going to try to avoid ranting about this, but its something of a bugbear of mine. In terms of JavaScript, I’ve noticed broadly 3 types of web developer (or maybe a combination of them):

  1. Ostrich Developers: These are developers who actively avoid writing JavaScript to the extent that you’d think it didn’t exist.
  2. Scrappy Developers: Here we see developers just writing functions in JavaScript – endless libraries of functions with little to no structure.
  3. Responsible Developers: These are developers that are trying to adopt or create best practice within their JavaScript and make well structured code. Maybe object oriented and maybe namespaced – but written in a structured, re-usable and understandable way.

Before I go too much further I must confess that I am guilty of avoiding JavaScript and writing endless libraries of functions – but I’m really trying to change for the better!

Why Are Developers Avoiding It

I’ve always found this interesting – maybe because JavaScript was one of the first languages I learnt – but the reasons I’ve come up with are:

  • The tooling is poor – most tooling for JavaScript is pretty damn awful – event now. I’m happy working in JavaScript, but I’d be lying if I didn’t admit that intellisense is sorely missed.
  • Using 2 languages is too complicated – I think for some people the thought of using one language server side (normally strongly typed) and then a different one client side (JavaScript – dynamically typed) is just too much. 2 different paradigms, 2 different languages and 2 very different approaches.
  • The framework is too good – By this I mean the framework which allows people to avoid getting their hands dirty with JavaScript. The main driver for people doing JavaScript has been AJAX – and frameworks like ASP.NET provide excellent facilities for masking the nuts and bolts with features such as update panels and built-in client validation. It makes it too easy to not understand what’s going on!

Why it matters

Its the most widely deployed runtime environment in the world. Its supported in practically every operating system in the world – combined with HTML5 it practically is an entire operating system. On almost every platform ios, android, windows there are ways to developer native applications using nothing more than html5 and JavaScript. Just accept that JavaScript is everywhere, and its there to stay!

What do we do about it

I see a few things we can do about this:

  • Stop avoiding it – if its hard, do it more and it’ll get easier.
  • Don’t write any more standalone JavaScript functions, I literally mean don’t write a single one of them! Encapsulate everything in JavaScript objects or at least namespaces.
  • Start unit testing your JavaScript – you unit test everything else (don’t you?!) – then start testing your JavaScript. QUnit is easy to understand, and can be integrated into your continuous integration environment. (If you need help with this kind of thing, give me a shout)
  • User libraries better – look at what JavaScript libraries you’re using – I can almost guarantee that they have hidden gem features that will really clean up your code. Like writing a plug-in in JQuery – its simple to do, and extremely powerful. Don’t be afraid to give it a go!
  • Stop making excuses – it may not be a perfect language, it may not be the fastest, you may not have chosen it – but it is what it is

What else!

The thing that motivated this little rant is that I just looked at Microsoft’s TypeScript after reading Scott Hanselman’s blog. TypeScript is essentially a superset of JavaScript that ‘compiles’ down to regular old JavaScript – a bit like how Mindscape Web Workbench ‘compiles’ Sass, Less and CoffeeScript files down to their respected subset. I haven’t had chance to use TypeScript yet but I already like the look of it – in my mind it makes writing good / structured JavaScript much simpler, and with much better tooling.

So from now on I’m going to write more JavaScript and write it better!


The Essential App Marketing Kit
Subscribe To My Newsletter To Get an Entire Chapter From The Book for FREE
Never display this again
0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×