37

Why is there just support for JavaScript and some VBScript in browsers today? I know JavaScript is good and all, but wouldn't having the option of using another programming language help promote different development styles?

jmort253
  • 9,347

10 Answers10

35

There is no need to add support for multiple languages, a solution would be to standardize on a generic bytecode that could be used by language implementors. But there are currently no plans for this (it's been suggested).*

Languages can be implemented on top of Javascript too. Javascript is good enough to allow other languages to be implemented on top of it. And there are many examples of this already.

(*) Update from 2022: today we have a standard for this (WebAssembly) which is supported by all major browser engines.

Doc Brown
  • 218,378
nkassis
  • 451
24

Think of the inconsistencies between browsers for their support of javascript alone. Now think about how it would be if there were more languages.

Michael Brown
  • 21,822
23

JavaScript is the de-facto standard and has been since 1996. Being a standard simply because there is no competition isn't exactly fair, but I haven't heard a lot of complaining about why there isn't another language included.

Adding another "standard" language promotes all sorts of fun little issues.

  • How will they work with other languages?
  • Will the DOM be shared?
  • Could scripts written in both still work?
  • Porting libraries to both
Josh K
  • 23,029
  • 10
  • 67
  • 100
7

Browsers have to be standardised, so that what you develop works everywhere, on all browsers.

If you have multiple languages kicking about, then you have to ensure that they all perform very similarly. If you are a web developer and you have a choice of languages, which may or may not be supported in some locations, then that is an additional headache.

Javascript is a very flexible language, it is imperative, it is functional, it can be OOP (after a fashion with prototypes), and it is interpreted. Now with decent engines like in Chrome, it is reasonably capable of doing some good stuff. Extra languages would just set things back here, look at VBScript, IE only, and so anything that is written in it is bound to a particular browser and platform, nightmare.

Orbling
  • 5,686
3

Instead of building these into browsers, vendors like to build clunky browser plug-ins - Java, Flash, Silverlight, etc. This guarantees cross-platform consistency.

2

One of the reasons is that it is practically impossible for different browser vendors to even agree on a standard Javascript implementation and Javascript has been around forever, at least from a web language perspective. So most people rightfully think that getting another client side language into the ecosystem and getting all the vendors to support it is practically impossible and most of the people that could potentially make it happen are already involved in Javascript standardization issues which I think is a much better use of their time.

2

There are several responses here which claim that supporting multiple languages would make it very odious for builders of web browsers to ensure they're compliant with all the languages. To me this seems incorrect.

Java, for example is an extremely well defined standard. Essentially, all you need to do is to expose the browser DOM as a Java API, and run the Java Virtual Machine (JVM) inside your web browser. You could specify that scripting code would either have to be delivered in the form of compiled and signed JAR files, or as JavaScript sourcecode. If the browser encounters JavaScript, it could either run it through a dedicated interpreter (as it does today), or through Rhino on top of the JVM. If it encounters jar files, it creates a new class loader and security sandbox, loads the java bytecode into memory and executes it. This would be completely backward compatible with existing web pages, and would allow the browser, with a single stroke, to support the dozens of languages that run on the JVM.

Other Advantages:

  1. The JVM has benefited from a decade of performance improvements. It is now very fast, stable and mature. I’m betting you’d see a big performance improvement over interpreted javascript.
  2. As client-side apps get larger and more complex, the benefits of structured, typed languages such as Java and Scala increase.
  3. You would have access to true multi-threading, and through Scala, a collections library optimized for multi-core computing.
  4. You could use any of the thousands of open source java libraries inside the browser.
  5. Through libraries like openGL, the browser could provide access to advanced graphics and graphics-card computing capabilities.
  6. If you had java running on the client and server side, you could further benefit from client-server communications via extremely compressed, binary object-graph serialization = faster loading and performing web pages.
Matthieu
  • 4,599
1

I believe JavaScript is going to gain even more ground as the standard language for the Web. We're seeing a rise in server-side JavaScript. Here are some examples of implementations of this powerful language on the server:

  • POW Web Server SJS - Server side JavaScript for the POW Web Server, which runs as a Firefox Extension or as a XULRunner Application. SJS plays a similar role to that of PHP in Apache in that it can connect to databases and generate client-side content.

  • NodeJS - Server side JavaScript that uses an event-based model. It is built using Google's V8 JavaScript Engine. NodeJS is advertised as being a tool for building scalable network programs. A "Hello World" Web server can be written in only 6 short lines!

  • Jaxer - A JavaScript server that interprets all script blocks with runat="server" as server-side JavaScript. Entire Web applications can be written in JavaScript.

  • Rhino - JavaScript for Java - Mozilla created this server-side JavaScript implementation that runs on Java. It's essentially a similar concept to Querces PHP for Java, Jython, JRuby, and many other abstractions of other languages that run on the JVM. Rhino is typically used to embed JavaScript into Java to provide scripting tools to end users, but it could also be used to move client-side code to the server without having to rewrite the business logic in another language!

  • JQuery Claypool - Server-side JavaScript framework using the power of JQuery on the server. Very cool! It's developed using the EnvJs Server-side JavaScript implementation of a browser.

  • EnvJs - A headless browser built on top of Rhino.

What many of these implementations and frameworks demonstrate is that JavaScript is becoming such a powerful force in Web development that community leaders have already started moving JavaScript to the server. JavaScript is an extremely powerful functional programming language, and as time goes on I feel we will see it evolve.

In summary, it seems like a contradiction to port the other languages to the browser when instead we can port this single browser language to the server and bridge that gap in a more unified manner.

jmort253
  • 9,347
1

There are several examples of tools which will compile other languages to javascript, including Haskel, Lisp and Python (Probably others). So if you want to work in one of those languages you can do so.

And I think one of my professors from university wrote a scheme implementation in Javascript. So if you like scheme you can do that too.

Zachary K
  • 10,413
0

People have worked around the lack of built-in variety in two ways: using plugins like flash or java applets, and building layers that sort of use javascript as their "machine code", like jquery or google web toolkit. If there was a new development style popular enough, people would find a way to get it in.

Just be aware if you make a .net runtime in javascript, and it ever becomes popular, certain circles will curse your name on the internet forevermore.

Karl Bielefeldt
  • 148,830