You Need to Learn JavaScript

You Need to Learn JavaScript


JavaScript is the most important programming language you can learn.

Now before you summarily dismiss the rest of this article or begin rage commenting – take a breath… and give it 5 minutes. I’m not saying JavaScript doesn’t have problems and I’m not saying it’s necessarily the best programming language. I’m saying it’s the most important. I’ll explain myself in a bit.

First a few clarifications…

JavaScript != jQuery

This was me a few years ago. The only JavaScript I wrote was to manipulate a DOM element here & there. I’m not sure I even knew that an API for the DOM existed outside of what I could do with jQuery. My JavaScript was usually some gnarly spaghetti code spread between a few files and several script tags, but it got the job done where needed. (I would like to formally apologize to those developers who had to maintain that code). I was doing it wrong. I was missing all the good parts because I didn’t know JS. If you are still writing JavaScript spaghetti code (because you can) – you’re also doing it wrong and you’re missing out on some of the language’s greatest strengths – such as code modularization. I will maintain that JavaScript if written correctly is more maintainable and durable than any of your standard class based languages. But that’s a future blog post.

 

JavaScript is a Server-Side language

Ok – yes it’s still a client-side language, but thanks to node.js it runs on the server too. This is kind of a big deal. Look how easy it is to write a web server:

server.js

If some of that syntax looked a little strange it’s because I’m using some es6 features. More on that later. Running JavaScript on both the server and client also allows for the development of Universal/Isomorphic JavaScript applications that share the same codebase on both server and client. Neat!


Ok. Enough with the housekeeping. Now that we’re all together in the wonderful new world of JavaScript possibilities. Let’s get to the meat & potatoes.

 

Top 6 Reasons why JavaScript is the most important language to learn:

1. Functional Programming

Why oh why did it take me this long to discover the beauty (yes beauty) and simplicity of functional programming? Functional Programming encourages writing stateless programs with immutable data structures – which means significantly fewer bugs and more maintainable code. If you want a more in depth look at the benefits of functional programming check out Why Functional Programming Matters – by John Hughes). Yes that paper was written 25 years ago – and probably more relevant today than when he published it. If you don’t have the time right now to read it – then here’s the TL;DR;

Functional Programming allows for modular code which makes simpler, cleaner, better programs.

Yes I know JavaScript is not the only or even the best functional programming language out there. However, I will argue that JavaScript will be the first exposure most developers will ever have to that paradigm. That was certainly true in my case. I was never exposed to languages like Haskell, Clojure, or Erlang, etc.

I’m not sure functional language courses were even offered when I was earning my degree. No – it was All Hail the Mighty Object Orientation using Java and a smattering of C++. JavaScript opened my eyes to the fact that all might not be well in the kingdom of Object Oriented programming. (see also this video, and this post, and any of these articles). JavaScript is everywhere (see item #3 below) and if we teach it correctly – JavaScript will be the vehicle for better software all around. A more in-depth look at Functional Programming will also be forthcoming in a later post.

 

2. Prototypal Inheritance

This one sort of dove-tails off of the last point – but it’s important enough to merit it’s very own bullet point. If you’re not familiar with prototypal inheritance you can read this. But the basic point is this: Prototypal Inheritance gives you the benefits of inheritance without the extra baggage (bugs) that you get with classical inheritance.

Prototypal inheritance is a core feature of JavaScript. It’s incredibly powerful and more performant than alternatives because prototypes are shared among all members lower in the chain. Combine prototypal inheritance with the benefits of functional programming and you’ve got something magic. A classical inheritance heirarchy quickly becomes brittle and difficult to maintain. Programmers cannot predict the future and eventually a feature request will come that you weren’t expecting and will break your taxonomy. I will dig more into this subject in the coming post on functional programming. In the mean time – much smarter people than I have extolled the many virtues of prototypal inheritance — so I’ll direct you to them if you still need convincing:

 

3. Ubiquity

ubiq·ui·ty: presence everywhere or in many places especially simultaneously

Whether you like it or not JavaScript is everywhere. I could show graphs and statistics to demonstrate this, like how it’s the most active language on github, or how it has the largest module repository, but I won’t. The plain fact is that the Web is eating the world and JavaScript is the language of the Web. Even in the burgeoning world of the Internet of Things, JavaScript is a front runner. (Check out cylon.js … so cool). A language that has that much reach can be a powerful force for either propogating bad programming practices & dogma or it can be used to promote better software utilizing the features mentioned above.

 

4. Learnability

That’s totally a real word. Right? Anyway – the ease of learning a language will have a big impact on it’s adoption in the community. A large factor contributing to #3 is that JavaScript is :

  1. easy to obtain
    • All you need to start developing is a browser. You’ve already got that. Most browsers include pretty fancy developer consoles that include console, debugging, and code inspection features. If you want to get a little more serious – just install node.js which comes with npm (package manager) and the REPL runtime. seriously… cake.
  2. easy to learn
    • JavaScript is dynamically-typed, script-based, and (as mentioned above) ubiquitous. That means there’s lots of documentation and examples everywhere. Since it’s a scripting language a new developer can jump right in – no need to learn the specific constructs of creating a program (like figuring out which standard headers to include how to define a main function).
  3. easy to debug
    • I already mentioned the debugger that comes with the browser. Node.js also comes with it’s own debugging api. However – there are several additional modules that make developing and debugging a breeze. (eg. node-inspector, vorlon, nodemon, and browser-sync).

 

5. NPM


I can’t sing enough praises for the Node Package Manager. I’ve talked about the modularity that the functional nature of JavaScript provides. NPM capitalizes on that feature with enormous success. I also mentioned how it is now boasts the largest module repository of any programming language.

Of course JavaScript is not the only language with a package manager or some other type of dependency management, but in my experience it is by far the simplest – and most powerful. Modules are versioned with semantic versioning using a notation that allows you declare the dependencies for your project with varying degrees of specificity for major, minor and patch versions.

Sub-module dependencies are transparently handled by the npm command-line utility which comes bundled with the node installation. The utility also comes with various other commands that allow you install, upgrade, clean, run custom scripts, run test suites, publish, yada, yada…. you get it. It’s all kinds of awesome.

However best feature of NPM in my opinion is the fact that all modules are open source. Aside from the fantastic benefit of the automatic induction into a huge community of developers who share their code openly – this also provides access to hundreds of thousands of examples of functioning modular JavaScript code. If you want to learn how a particular module works (or even better contribute to an open source project) just run

npm install and look at the code – or clone it from the documented repository.

6. ES6

One of the biggest complaints (and in my opinion, the main reason for the existense of jQuery and underscore.js among other libraries) is horrendously slow rate of updates to the language itself. It’s easy to complain, but I can only imagine how difficult this problem has been to solve. Up until recently the sole target for JavaScript was the web browsers, which have historically been incompatible with each other – let alone any kind of single standard. Trying to maintain a language specification to operate in that chaos seems daunting at best.

The good news is that Web Browsers are finally starting to play nicely together (Thank you Microsoft Edge! – I’m now looking at you Safari). TC39 (the group that manages the ECMAScript specification) just released the biggest update to the language since its creation. To prove that they are committed to continuous timely updates they named this release ECMAScript 2015. I know – eww. But I can’t argue with the rationale that it holds them to their commitment to release yearly. I can happily put up with a gross version name in turn for keeping the language polished. All the cool kids are still calling it ES6 anyway.

If you haven’t developed in vanilla JavaScript in some time – now is a fantastic time to come back to the fold. I won’t judge. ES6 offers some fantastic new features that make the language even more powerful. This is another future blog post, but here’s a sneak peek of some of the good stuff:

The astute reader may have noticed that I left out the new class construct that was added in es6. I can not in good conscience recommend this tragedy in any shape or form. Again… this is another post entirely – or you can read this.

 


 

You may not agree with my assertion that JavaScript is the most important language to learn, but I hope to have at least piqued your interest in learning some of the better aspects of the language. My reasons for this assertion is that learning JavaScript will inherently expose you to some of the better programming concepts that you may not find so easily other languages. Stay tuned for a more in depth treatment in many of the topics discussed and let me know your thoughts in the comment section.

Ultimately – “Software needs to be better“. On that note, I’ll leave you with these fine words of wisdom:

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *