9

I come from a scientific biology background where we also use Python a lot.

Now that I've begun to start with Web development, I've consistently found myself wondering just why it is that JavaScript is the primary client-side language on the Web.

Is JavaScript's predominance a historical accident or something else? Also, I'm curious if there are any hurdles to integrating Python into client-side scripting?

4
  • Does this need moderator attention based on meta.programmers.stackexchange.com/questions/363/… ? Commented May 7, 2011 at 2:17
  • @Rein - You could vote to close if you feel this is off-topic. If others feel the same way, either they, or a moderator, will follow your lead.
    – jmort253
    Commented May 7, 2011 at 2:32
  • @jmort253 (Perhaps I should move to meta) There wasn't consensus in the thread linked and I am ambivalent. :( Commented May 7, 2011 at 2:34
  • @Rein - The thought process in comments is okay (as it serves as a signpost, as to why or why not, the community decided to take action on a post. If there's no agreement, then do what you think is best. :) Personally, I think this historical information could help others understand the future of JavaScript as a language and why it's important to understand and adopt this language.
    – jmort253
    Commented May 7, 2011 at 2:41

5 Answers 5

16

JavaScript was the first scripting language to be made available in a popular Web browser, so it was implemented almost universally. Being the only programming language available in all popular browsers, there was no choice but for it to be the predominate client-side programming language.

Internet Explorer implemented JavaScript in a way that allows pluggable scripting engines (it came with VBScript and JScript). If you preferred (as I did) to write your code in PerlScript or PythonScript, you could, but all of your clients had to have that script language installed, and they had to use IE. You could do this for internal projects, but there's no way it would ever work on the Internet.

3
  • Something else which I found interesting were projects to write python-to-javascript compilers, e.g. Pyjamas pyjs.org.
    – rd108
    Commented May 10, 2011 at 0:33
  • "Pyjamas is a Rich Internet Application (RIA) Development Platform for both Web and Desktop. It contains a Python-to-Javascript compiler, an AJAX framework and a Widget Set API. Pyjamas started life as a Python port of Google Web Toolkit, the Java-to-Javascript compiler. Read the FAQ and the list of features."
    – rd108
    Commented May 10, 2011 at 0:36
  • There are tons of something-to-javascript compilers. CoffeeScript, TypeScript, ClojureScript, LispyScript, etc etc. Commented Dec 6, 2012 at 8:48
7

JavaScript was originally created by Brendan Eich. It was first shipped with the beta release of Netscape Navigator 2.0 in September 1995 as LiveScript but was renamed JavaScript in a joint announcement with Sun Microsystems in December 1995. It was only later (in 1996) that JavaScript was submitted to Ecma International and eventually became the standardized ECMAScript.

Its current market dominance is largely due to historical inertia.

Source: http://en.wikipedia.org/wiki/JavaScript#History

2

Not sure, but it's a lightweight, clientside scripting language. I think its origins lay with early Netscape browsers (though I could be wrong). Indeed, its very name was changed before release to include the word "java" even though it had nothing to do with java. It was a quick tactic to gain popularity at the time.

1

I am sure it has a lot to do with history.

But I am also sure I do not want websites to be able to run full featured programing languages like python on my browser. The security implications would frighten me away from any site like that (or I would have to be very very certain the browser sandbox was air tight).

3
  • That does not make sense. IT is up to the environment to decide which APIs are available for a programming language. Of course, if Python was shipped in browsers, it would have access to the same APIs Javascript has now (like the DOM), so it would have no way to create any damage.
    – Andrea
    Commented May 7, 2011 at 12:02
  • @Andrea - you could argue that a language is as much its standard libraries as its syntax and semantics. Javascript doesn't have a standard library for file I/O, and that's intentional, for security reasons. Python has standard libraries for file I/O, and for a lot of other things that might be considered security issues. Disallow these and arguably you're not dealing with Python any more. A long time ago, Python had a sandbox - I remember it being there around version 1.5 - but is was dropped IIRC because it wasn't used enough, and was far from air-tight.
    – user8709
    Commented May 7, 2011 at 21:04
  • Standard libraries for I/O in Javascript are being written. Of course these are not available in the browser. I'm justg saying that if Python was implemented in the browser, unsafe libraries would not be available. And presumably you would not miss them, since they are not meant to be used on a website.
    – Andrea
    Commented May 8, 2011 at 7:14
-2

"Is JavaScript's predominance a historical accident or something else?"

I am personally of the opinion that JS's success is a matter of design as much as many have been and will continue to be loathe to admit it and not just some accident or merely due to the fact that it was the first kid on the playground.

Though named so as to appeal to Java developers and syntaxed like Java's C-based syntax also to appeal to Java developers, Brendan Eich made one of the most badass decisions in the history of the www which was to draw primarily from Scheme for actual language mechanics inspiration, which is something Java developers don't appear to have liked very much at all (which I find highly amusing).

JavaScript uses highly flexible/granular prototypal inheritance for OOP, it has closures, types are 100% dynamic, functions themselves are first-class allowing them to be passed around like any other object or data type and get re-used in different contexts and even get applied to objects on the fly as if they had been declared as actual object members from the start. It is practically screaming to be used for event-driven architectures that need to normalize a ton of proprietary garbage or handle highly non-linear UI problems.

At the end of the dawn of the web it is the only language that has ever been seriously up to the task of normalizing browsers through an actual browser war where Netscape and IE tried to do things differently on purpose, followed by 10+ years of browser truce where IE just did things differently because MS is lazy and self-entrenched into some righteously stupid anti-competitive practices resulting in browser stagnancy, and now a world where the browsers are finally starting to agree on the same general spec in regards to HTML, CSS and the DOM API with IE merely being 2-3 years behind the latest developments rather than 10 owing to Google and Mozilla busting out JIT compilers that made IE's performance numbers look so pathetic MS was finally shamed into properly modernizing their damn browsers. IE9 is the first to actually seriously upgrade the DOM API support to levels that Netscape was supporting back in 2000ish.

JS has had competition in the form of Java Applets and Adobe's ActionScript for Flash. That's about it on the serious contender front. MS tried to push VB but failed miserably because... well... VB. Also, proprietary. There were actually a lot more Flash sites than most people realize. You just couldn't find the silly things with search engines. Applets did their own thing, and it was ugly. Real ugly. JS was the only language that really tackled the problem of working within the context of multiple browsers by people who didn't agree on who was setting the specs they were supposed to be matching up with.

In recent years JS has been exploding into a much wider domain of application. In combination with other web technologies it is geared up to basically knock all other solutions over on the mobile front since it + web technology is really the only realistic choice right now if you really do want to write one app and have it work on everything.

So no, and yes I'm a big fan, but I don't think it clobbered all other contenders on the client-side by accident any more than it becoming explosively popular outside of the browser could be considered an accident now. Before JS, there weren't many Scheme-like languages out there that weren't primarily academic. That's given JS some powerful advantages and the unique needs of the client-side made it possible for those advantages to slowly become crystal clear.

9
  • You mention Scheme twice without ever saying how JS relates to Scheme. Certainly you don't think JS has macros, S-expressions, tail recursion, continuations, or any of the other distinguishing features of Scheme -- do you?
    – Gabe
    Commented Dec 6, 2012 at 14:17
  • @Gabe. Check the 4th block of text. Closures, dynamic typing, and first class functions are pretty major. The fact JS uses c-like syntax will disallow the use of Scheme macros. It's not a feature-by-feature copy of Scheme but it is certainly influenced by it.
    – mike30
    Commented Dec 6, 2012 at 14:41
  • So closures and dynamic typing makes a language Scheme-like? Does that mean C# is Scheme-like? What about Ruby, Python, and Perl? And why Scheme rather than Lisp or any other similar language?
    – Gabe
    Commented Dec 6, 2012 at 16:27
  • @Gabe I'm no Scheme expert but on casual wikipedia-ing I'd say the combo of lexical scope, first-class functions, and closures are the three that put JS a lot closer to Scheme than it is to Java. Otherwise I was just taking Brendan Eich's word on it and assumed proper first-class functions were the major standout. Commented Dec 6, 2012 at 17:16
  • OK, so JS has closures (which I believe implies first-class functions and lexical scoping) and dynamic typing, like Scheme. Since C# has closures, dynamic typing, and a limited form of S-expressions, does that mean C# is even more Scheme-like than JS?
    – Gabe
    Commented Dec 6, 2012 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.