Why JavaScript?

 

Here in the Wild, Wild West we have a saying: "Beware of the man with one gun — he probably knows how to use it!" It would be one giant leap for mankind if we could say the same about programmers and their languages. Because, what the world really needs is an easy to learn, universal, high-level programming language that is powerful enough for professional programmers and simple enough for non-professionals to do real, practical work in their own domain — without any need for detailed knowledge of computer systems. It need not be a speed demon, but it must run fast enough the difference isn't really noticed. JavaScript, the world's most "misunderestimated" programming language, is presently the only solution meeting these requirements. This is, no doubt, why JavaScript is already one of the two most widely used programming languages. The other, of course, is C (and its derivative C++). Java, which is a completely different language from JavaScript, runs a distant third and everything else is an also ran. (Java is the official programming language for Android applications but they still comprise only a fraction of the code in actual use and development).

While extremely powerful, C/C++ is a complex, low-level language, in practice accessible only to professionals. Everybody "uses" it, in the sense that all modern operating systems and the vast majority of software packages are created with it (by professionals). But, unfortunately, C/C++ is far too unwieldy for occasional use by engineers, scientists, business people and students — which is why it cannot ever be considered a truly universal language. And, even for professionals, it takes a great deal of time and effort to code and test even the simplest programs in C/C++ — which is why so many other languages have been invented. Languages like Perl, Python, etc. all have their (often fanatical) devotees, and all have their uses, but none have ever been used as widely as C/C++ and JavaScript. On the other hand, everybody already "uses" JavaScript, in the sense that most professional web pages include at least some embedded JavaScript code — which is executed within the web browser itself, when the page is downloaded and displayed.

By a quirk of fate, JavaScript is the only practical programming language for the "client" side of modern web based applications. While every major web browser in the world is itself written in C/C++, every web browser in the world also includes a JavaScript engine. It has to, because the Document Object Model (DOM), required for the web to work, literally is JavaScript. And that cannot be changed without completely redesigning and rewriting the entire World Wide Web (which isn't going to happen any time soon). So, since JavaScript is already required for half the world's programming, it might as well be used for the other half as well.

Fortunately, JavaScript is as well suited to that other half as it is to web pages:

♦ JavaScript is very easy for non-professionals to learn and use at a basic procedural level — hence its wide adoption by web developers. But, for professional programmers, it is also a powerful, expressive, high-level language, well suited to all general purpose programming. It uses dynamic typing of variables, rather than requiring them to be laboriously predefined (which often requires detailed knowledge of hardware architectures). Any variable can contain any of the small, simple set of JavaScript data types. They are automatically "garbage collected" when no longer in use, largely eliminating the complexities of memory management (the largest single source of bugs in C/C++ programs). The JavaScript "object model" is much simpler than the class-based model of C++ and Java, but just as powerful, and it even allows objects to be dynamically mutated during program execution. These features make JavaScript one of the easiest languages to learn and one of the most productive for professional coding and development.

♦ JavaScript is, technically, an interpreted scripting language. This eliminates the complexities of compiling and linking source code modules into an executable program — which can often be confusing for non-professionals. Obviously, this does have a negative impact on JavaScript performance but markedly less so than many detractors would claim. Modern JavaScript engines, included with all common web browsers, are forced by competitive pressures to continually upgrade their performance. The one we have chosen for JSUS, the V8 engine from the Chrome web browser, actually compiles JavaScript into a self optimizing sequence of machine code instructions. This is not quite as powerful as a fully optimizing C/C++ compiler, but the resulting performance is significantly faster than other scripting languages and pseudo code languages like Java. This performance is already sufficient for general purpose applications and, given competitive demands and ever increasing processor speeds, it can reasonably be expected to improve still more in the future.

♦ JavaScript is implemented as a self-contained "engine", specifically designed to be easily embedded within all kinds of containing programs. Most obvious, of course, is the web browser itself. But, JavaScript engines are also usefully embedded within word processors, spreadsheets, databases, etc. Effectively, our JavaScript Unix Shell (JSUS) embeds the V8 engine within the operating system itself. JSUS encapsulates the most important functions from the C runtime library and registers these with V8 as "callback" functions. In turn, these are added to the global object and can be called from JavaScript exactly like all other builtin functions. This approach allows JSUS (and other programs) to greatly expand the functionality of the JavaScript language — which offers little builtin functionality of its own. And, because the callback functions are written in C++, they can provide major enhancements with even better performance than native JavaScript (for example, the Memory Mapped I/O used by our database manager).

♦ JavaScript is fun, productive and creative. As time goes by, programming in C, C++, Java, etc. becomes more and more boring. Subjectively, in low-level languages like these, more than 50% of developer time is wasted on tedious housekeeping chores unrelated to the application itself — memory management, type definitions, over-engineered class libraries, etc., etc. And, it seems, the drudgery is worst of all when it comes to the Graphical User Interface, or GUI. In JavaScript, many of these chores disappear and the GUI library magically morphs into simple HTML 5 and embedded JavaScript, sent to a standard web browser as easily as printing text on the console. As a result, the developer spends more of his time on the actual application and he is happier, more productive and more creative. Add in the fact that, as a true high-level language, JavaScript requires only a fraction of the lines of code to achieve the same result as in C/C++ and there really is no comparison.

So, why JavaScript? Because it is the only viable candidate for a truly universal programming language. It offers reasonable performance and is easily learned by non-professional programmers. It can be easily extended, almost without limit, without modifying the language itself. And, it is an order of magnitude more productive than C/C++ or Java.