-
Notifications
You must be signed in to change notification settings - Fork 18
A Misunderstood Language?
As you might know the first version of JavaScript was developed in mere two weeks at 1995 by a fellow named Brendan Eich over at Netscape Corporation. Mozilla can be considered a successor of it. You most likely recognize the name. Yes, they are behind the web browser. In fact they built that on the remains of Netscape.
Initially the language was known as LiveScript but the marketing men decided JavaScript sounds more convincing. After all it was the decade of Java so anything with Java in it must have felt like a killer product. And in a way the legacy of Java still lives on although not in the way envisioned. On retrospect it wasn't a good choice to name the language as JavaScript and a lot of confusion has ensued. Java is to JavaScript as ham is to hamster. Keep that in mind!
So how would you characterize JavaScript? Even though it looks a bit like Java or C due to bracing there it is actually an implementation of a couple of powerful languages in disguise. These languages are a variant of Lisp known as Scheme and Self. From former JavaScript inherited some of its functional programming capabilities whereas latter gave it prototypal inheritance system which in some ways can be considered superior to classical one used by languages such as Java.
It is possible to mimic the more commonly used one with a little effort, though. As a result there are dozens of implementations around. It doesn't take a genius to realize that this isn't particularly nice. ES6 aims to various implementations and will provide a single pattern to use.
Particularly JavaScript's functional capabilities make it in some ways an exceptional language. For a long while this power was well hidden, or at least not that well recognized. The language was improved in this regard in well supported ES4 (there are shims for older browsers). ES6 will take this a notch further.
Of course JavaScript comes with the usual imperative programming constructs (for, while, if, etc.) you might expect. There is also some legacy in form of Date and Math modules inherited from Java 1.0. There are some custom features even (with
comes to mind) though it is better to avoid some of those and just to stick to a solid subset.
You can get plenty of things done even with a well selected subset of the language. You will avoid some pitfalls and keep your code readable even for less superior programmers as you. Granted it is perhaps a bit more verbose than some might like.
Typing-wise JavaScript has been typed very loosely. Functions are treated as first class citizen. And everything is an object of course. It will take some getting used to. It isn't as bad as it might sound. Although it is one of those features that makes it very easy to shoot oneself into a foot. This is a risk that you can mitigate, however. Learn the language and use various tools. As usual with dynamically typed languages, testing is a very good idea.
Being loosely typed doesn't mean the language cannot perform, on the contrary. Particularly the last few years have yielded significant increases in performance. One key factor in this has been Google's V8 Engine. In fact that particular engine powers popular Node.js platform and is likely one of the reasons why it has become so popular.
Talks about JavaScript being slow are nonsense. Depending on your background it might feel intuitively so but fortunately it isn't. There was definitely a time when this was true but that isn't the case anymore.
Since JavaScript isn't really everyone's cup of tea, or coffee. Various languages that compile to JavaScript have emerged. Usually these languages provide some constructs not found in the core language. You may gain better type checking or some syntactical sugar.
altJS lists many of these languages. If you have time, go and check out a few. Personal recommendations: CoffeeScript, Dart, TypeScript, Elm.
Some daredevils use emscripten to run arbitrary code in JavaScript. It is a system built on top of LLVM and makes many perhaps a bit crazy things possible. You can for instance play Dune 2 or Transport Tycoon Deluxe in your browser. How retro is that?
JavaScript is a misunderstood kid. As the wise say, thou shalt not judge a programming language by its name. So please avoid that. Even though there's a J word in its name, it doesn't mean you will get pimples by using it. JavaScript is a surprisingly powerful, and these days popular, language that in essence is the language of the web. Learn it and the world shall bow before you.
Since in this chapter I more or less just waved hands around and hopefully piqued your interest enough, I recommend checking out the next chapter in which I examine the current state of JavaScript, our hero language.
Created by @bebraw. If you have ideas or happened to find some bugs, let me know over at issue tracker.