The Front Typing Department of the Live Taiping Company translated for Habr readers a great deal about the origin, development and prospects of the JavaScript language, published in the Auth0 service blog. Today we publish the first part of the translation. Netscape and Mosaic rivalry, dreams of an interactive web, a programming language for non-programmers, a transition from classes to prototypes, and what is common between JavaScript and ECMAScript (spoiler: everything).
JavaScript is probably one of the most important programming languages ​​today. Thanks to the development of the web, JavaScript has reached heights that it has not promised. In this article we will look at the entire path of JavaScript from creation to today and try to look into its future. ')
It all started in the 90s
Events, which resulted in JavaScript, unfolded within six months, from May to December 1995. Netscape Communications confidently made its way into the field of web technology. Her Netscape Communicator browser successfully won positions with NCSA Mosaic, the first popular web browser. Netscape was created by people who took part in the development of Mosaic in the early 90s. Now, with money and independence, they had everything they needed to find ways to further develop web technologies. This was the impetus for the birth of JavaScript.
The founder of Netscape Communications and former member of the Mosaic team, Mark Andrysen believed that the web should become more dynamic. Animations, user interaction and other types of interactivity should be an integral part of the Internet of the future. The web needed an easy scripting language (or scripting language - ed.) , Able to work with DOM, which in those days was not standardized. There was one “but”, which at that time was a serious challenge: this language should not have been meant for major developers and other people related to the engineering side of the issue. Java in those days was already actively developed and firmly occupied this niche. Thus, the new scripting language was supposed to be intended for a completely different audience - designers. Obviously, the web was static, and HTML was fairly young and easy to learn, even for those who had nothing to do with programming. Consequently, everything that should have become part of the browser and make the web more dynamic should be as clear as possible for people far from programming. From this assumption, the idea of ​​Mocha was born, which was to become that simple, dynamic and accessible scripting language.
And here in our history appears Brendan Ike, father of JavaScript. Ike should have developed a “Scheme for the browser” for Netscape. Scheme is a dynamic, powerful and functional dialect of the Lisp programming language with the most simplified syntax. The web needed something similar: simple to learn, dynamic, terse and powerful. Ike did not miss the chance to work on what he liked, and joined the team.
The team was tasked to prepare a working prototype as soon as possible. Sun Microsystems was finishing work on its Java programming language, at that time called Oak, and Netscape Communications was ready to sign a contract with the company to make Java available in its browser. So why do you need Mocha (the first name of JavaScript)? Why was it necessary to create a completely new programming language with a ready-made alternative? The fact is that Java was not designed for the audience that Mocha was targeting - scripters, amateurs, designers. Java was too big and heaped up to fulfill this role. The basic idea was that Java should have been designed for major developers and professional programmers, while Mocha should have been used for small script tasks. In other words, Mocha was supposed to be a scripting companion for Java in a way similar to how C / C ++ and Visual Basic interact on the Windows platform.
Netscape engineers have begun a detailed study of Java.They even began to develop their own Java virtual machine, but the project quickly collapsed, as it could not achieve perfect compatibility with the Sun Microsystems virtual machine.
The problem of the fastest choice of language was more acute than ever. Possible candidates were Python, Tcl and Scheme. Ike had to act fast. Compared with competitors, he had two advantages: freedom in determining the set of necessary capabilities and direct communication with the customer. Unfortunately, there was an obvious inconvenience: there was almost no time to make a huge number of important decisions. JavaScript, aka Mocha, was born in such conditions. Within a few weeks, a working prototype was prepared, which was then integrated into Netscape Communicator.
What should have been an analogue of Scheme for the browser, turned into something completely different. Ike's hand was controlled by the need to close the deal with Sun and make Mocha a scripting companion for Java. The syntax was to be as close as possible to Java. In addition, semantics for a large number of well-established idioms was inherited from Java. So Mocha was nothing like Scheme. It looked like dynamic Java, under the shell of which the Scheme and Self hybrid was hidden.
The Mocha prototype was integrated into Netscape Communicator in May 1995. After a very short period of time, it was renamed LiveScript, because at that moment the word live looked very attractive from the point of view of marketers. In December 1995, the transaction between Netscape Communications and Sun was closed: Mocha / LiveScript was renamed JavaScript and presented as a scripting language for performing small client tasks in the browser, while Java was a full-fledged professional programming language for developing complex web applications. components.
The first version of JavaScript laid all the fundamental features that this language is famous for today. In particular, its object model and functional features were already present in the first version.
It is difficult to say how events would have developed if Ike had not managed to provide a working prototype on time.Python, Tcl, Scheme, considered as an alternative, were completely different from Java.Sun would have been hard to accept as a companion language for Java options that were fundamentally different from it.Java, on the other hand, has long been an important part of the web.If Sun were not the determining factor, Netscape would have much more freedom to choose a language.But would Netscape develop its own language or use one of the existing ones?This we will never know.
Various implementations
When Sun and Netscape closed the deal, and Mocha / LiveScript was renamed to JavaScript, a very important question arose: what about competitors? Although Netscape was gaining popularity, becoming the most used browser, Microsoft was actively developing Internet Explorer. From the earliest days, JavaScript showed such amazing possibilities in terms of user interaction, that the competing browsers had no choice but to find ready-made solutions that were working JavaScript implementations as soon as possible. At that moment (and long enough after that) web standards remained fairly weak. Therefore, Microsoft has developed its implementation of JavaScript, naming it JScript. By removing the word Java from the title, they were able to avoid potential problems with the trademark owners. However, JScript was not only different in name. Small differences in implementation — in particular, the approach to some DOM functions — left a ripple that will be felt for many years to come. The fights for JavaScript went on a much larger number of fronts than the names and timelines, and many of the quirks of this language appeared thanks to them. The first version of JScript appeared in Internet Explorer 3.0, which was released in August 1996.
The JavaScript implementation got its own name in Netscape. The version released with Netscape Navigator 2.0 was known as Mocha. In the fall of 1996, Ike rewrote most of Mocha to deal with technical flaws and flaws that arose as a result of the rush to develop. The new version was named SpiderMonkey. This name is still used today in the JavaScript engine of Firefox, the grandson of Netscape Navigator.
For several years, JScript and SpiderMonkey were the only JavaScript engines. The features of both engines, which are not always compatible, determined the vector of web development for the coming years.
The main features of the architecture
Despite the fact that JavaScript was born in a hurry, some powerful features were laid out from the very beginning. These features defined JavaScript as a language and allowed it to outgrow its own boundaries, despite all its quirks.
“The decision to use ready-made language instead of inventing its own was in no way dependent on me.The installation from the very top sounded like this: “The language should look like Java”.This immediately dropped Perl, Python, and Tcl along with Scheme.Later, in 1996, John Ousterhout came to us to show Tk and be upset about the missed opportunity for Tcl.I’m not proud, but I’m happy that I have chosen the function of the first class as the main ingredients, similar to the Scheme and the prototype Self programming.The impact of Java, especially the 2000 year-old dates and case sensitivity, was an annoying misunderstanding. ” - Brendan Eich's blog: Popularity
Although creating syntax as close to Java as possible was not the main idea of ​​JavaScript, the market made its own adjustments. Perhaps a different syntax would be more suitable for solving certain tasks, however, thanks to the use of the familiar JavaScript syntax, it easily gained popularity.
Functions in JavaScript are just another type of object. They can be operated like any other elements. They can be bound to variables and, in later versions of JavaScript, even be thrown as exceptions. Most likely, this feature of JavaScript is due to Scheme.
Due to the fact that functions are considered as objects, various functional patterns have become possible:
var a = [1, 2, 3]; a.forEach(function(e) { console.log(e); });
These patterns are successfully used in many libraries, such as underscore and immutable.js .
Prototype programming
Although prototyping has become popular with JavaScript, it was first introduced to Self. Ike preferred this particular programming style, which turned out to be powerful enough to simulate a more traditional approach of Simula-like languages, such as Java or C ++. By and large, classes implemented in the modern version of JavaScript are nothing but syntactic sugar that is sprinkled with a prototype system.
The creators of Self, a programming language that inspired Ike to introduce prototypes in JavaScript, tried to avoid problems associated with objects in Simula-like languages. In particular, the branching between classes and instances has caused many of the problems inherent in Simula-like languages. The problem that arose when the program code developed and became larger was repeatedly discussed: since classes were an archetype for all new objects, as the code grew, it became more and more difficult to adapt the base classes to the new requirements that arose in the process. Such a problem can be avoided by making new instances of prototypes, from which, in turn, new objects would be created. This is the basic concept of prototypes: a sample that can set its own parameters. If the prototype was not suitable for a new object, it could be cloned and modified without exerting any influence on the other child instances. In class-based languages, this approach is extremely difficult.
Due to the strength of JavaScript prototypes, it turned out to be extremely flexible. In the wake of inspiration, developers have created a huge number of libraries with their own object models. The popular Stampit library squeezes everything out of a prototype system in order to manipulate objects in ways that are impossible in traditional class-based languages.
Prototypes made JavaScript deceptively simple, giving library developers tremendous power.
Big fad: primitives and objects
Perhaps one of the biggest mistakes made because of the haste in which JavaScript was developed was that objects that behave completely identical can be of different types. For example, the string type (Hello world) does not match the type of the new String object (new String ('Hello world')). This sometimes leads to undesirable consequences that can be confusing.
But this was only the beginning in the history of JavaScript. Hasty development has caused a large number of architectural errors that could become a real nightmare. However, the time was running out, and everything had to be left as is.
“Everything else is a perverse, ruthless story.JavaScript has become the most popular client-side implementation of Java, which only Flash could compete with, supporting ActionScript - a direct descendant of JavaScript. ” - Brendan Eich's blog: Popularity
On the waves of my memory: a look at Netscape Navigator 2.0 and 3.0
The first public version of JavaScript was built into Netscape Navigator 2.0, released in 1995. Thanks to the wonders of virtualization and outdated and unsupported sites, we can relive these moments of happiness.
Unfortunately, many basic JavaScript functions did not work at that time. Anonymous functions and prototype chains, the two most powerful features, did not work the way they do today. Nevertheless, these features at that time were already designed and should have come to life in the coming years. It should be noted that this version of the JavaScript interpreter was considered an alpha version.
To great joy, Netscape Navigator 3.0 was released a year later, and it was very different from its predecessor:
Please note, the error message gives much more information about what is happening. This, in turn, allows us to understand that the interpreter perceives the property of the prototype in its own way. We replace the object with the base instance of Object, slightly modify it, and - voila - everything works! At least partially. Apparently, the assignment within the test function does not do anything. It is quite obvious that there will still be a lot of work ahead, and yet, JavaScript in its current state could well be used for most tasks, and its popularity continued to grow.
Features like regular expressions, JSON and exceptions were not yet available. In subsequent years, the development of JavaScript occurred incredibly quickly.
ECMAScript: standardized javascript
The first big change for JavaScript after its release was ECMA standardization. ECMA is an association established in 1961 to standardize information and communication systems.
Work on the standardization of JavaScript began in November 1996. The standard that the TC-39 group was working on was assigned an ECMA-262 identification number. By the time JavaScript was actively used on many web pages. This 1996 press release lists 300,000 pages using JavaScript.
JavaScript and Java are at the core of Netscape ONE, a platform for developing Internet and intranet applications. Within a short time since its introduction last year, new languages ​​gained recognition among developers, thanks to which there are currently more than 175,000 Java applets and more than 300,000 pages using JavaScript all over the Internet, according to www.hotbot.com . - Netscape Press Release
Standardization has become for the young language not only an important step, but also a serious challenge. It opened JavaScript to a larger audience and provided an opportunity for third-party developers to participate in the development of the language. She also helped keep other developers in line. At that time there was a fear that Microsoft or anyone else might deviate too much from the original implementation of the language, which could lead to fragmentation.
Due to trademark issues, ECMA could not use JavaScript as a name. After a short debate, it was decided that the programming language described by the standard would be called ECMAScript. Today JavaScript is just the commercial name of ECMAScript.