views:

432

answers:

15

At the moment, the only fully supported language, and the de-facto standard for DOM tree manipulation in the browser is JavaScript. I just started playing with this language, so I don't know much of it, but after reading some stuff around, looks like it has deep design issues that make it a minefield of bugs and security holes for the novice. Despite this, I sort of like it, so I don't have a grudge against the language. Please don't assume I am trolling. I am not. I'm just curious.

My question is: do you know of any existent or planned initiative to introduce a better (redesigned) language of any kind (not only javascript) for DOM tree manipulation and HTTP requests in next generation browsers? If yes, what is the roadmap for its integration into, say, Firefox, and if no, for what reasons (apart of interoperability) should be JavaScript the only supported language on the browser platform ?

Edit: I forgot to say that I already used jQuery and I also read "javascript: the good parts". Indeed the suggestions are good, but what I am not able to understand is: why only javascript? On the server-side (your-favourite-os platform), we can manipulate a DOM tree with basically every language, even fortran. Why the client side (the browser platform) supports only javascript ?

+1  A: 

In terms of client side Javascript is the only way to manipulate the DOM. In terms of server side there are a multitude of ways.

Ben Shelock
+3  A: 

The problem with javascript is not the language itself - it's a perfectly good prototyped and dynamic language. If you come from an OO background there's a bit of a learning curve, but it's not the language's fault.

Most people assume that Javascript is like Java because it has similar syntax and a similar name, but actually it's a lot more like lisp. It's actually pretty well suited to DOM manipulation.

The real problem is that it's compiled by the browser, and that means it works in a very different way depending on the client.

Not only is the actual DOM different depending on the browser, but there's a massive difference in performance and layout.


Edit following clarification in question

Suppose multiple interpreted languages were supported - you still have the same problems. The various browsers would still be buggy and have different DOMs.

In addition you would have to have an interpreter built into the browser or somehow installed as a plug in (that you could check for before you served up the page) for each language. It took ages to get Javascript consistent.

You can't use compiled languages in the same way - then you're introducing an executable that can't easily be scrutinised for what it does. Lots of users would choose not to let it run.

OK, so what about some sort of sandbox for the compiled code? Sounds like Java Applets to me. Or ActionScript in Flash. Or C# in Silverlight.

What about some kind of IL standard? That has more potential. Develop in whatever language you want and then compile it to IL, which the browser then JITs.

Except, Javascript is kind of already that IL - just look at GWT. It lets you write programs in Java, but distribute them as HTML and JS.

Keith
I'd say it's "interpreted", not "compiled" by the browser.
Flavius Stef
Newer browsers do JIT compilation on the JavaScript.
Nosredna
Huh? JIT compilation? Not really - What the latest browsers do that makes them so fast is essentially creating underlying classes for Javascript objects (that are actually just dictionaries) and adding garbage collection. JIT refers to compiling the code into an intermediate language which is distributed - Javascript is always raw code.
Keith
I also googled the jit claim, and, as it turns out, Firefox 3.1 will have the support built in. Check out http://andreasgal.com/2008/08/22/tracing-the-web/ or http://people.mozilla.com/~schrep/tm-image-adjustment.swf
Flavius Stef
The V8 JavaScript engine (chrome) compiles directly.
Dave W. Smith
@Keith: Actually JIT (just-in-time) compilation refers to compiling code after distribution, on the client, into machine code. It sounds like you were trying to describe compiling to Java bytecode or MSIL.
Jay Michaud
@Jay Michaud - quite right, but what I'm getting at is that intermediate step. JIT compiles the IL at the last possible moment (hence the name) - i.e. on the machine the first time that the application runs. However you still have that initial 'compile' into IL. In order for Javascript to use JIT (as anything other than an internal interpretation step) you would have to get some sort of JSIL in web pages instead of the raw code.
Keith
"some kind of IL standard": Very good remark! One might expect that it would be possible to make such low level language (together with a foundation library) cross-OS and cross-browser. This would make it a lot easier to build web applications.
Dimitri C.
+10  A: 

It is true that Javascript was at one point notoriously hard to deal with but the web development community has come a long way since. Instead, I would encourage you to have a look at jQuery. It's easy and abstracts away all the various problems.

And there really are no alternatives that work across the board. Flash comes to mind but that too is ECMA script and it's probably over kill for most things.

aleemb
or MooTools, Prototype, and Dojo. http://jqueryvsmootools.com is a great comparison between mootools and jquery.
rpflo
There is/was nothing inherently wrong with Javascript. You're likely referring to problems in IE's JScript and general rendering issues and inconsistencies with various browsers.
Robotsu
+1  A: 

No. JavaScript is it, but it will evolve. The next version is "JavaScript Harmony," and you can learn more if you Google that.

Now and then someone suggests putting a byte code interpreter into the browsers alongside JavaScript. Probably won't happen, at least for awhile.

I happen to love JavaScript. But there are other solutions, including GWT, which compiles Java to JavaScript and Script#, which compiles C# to JavaScript.

Nosredna
+2  A: 

Internet Explorer supports pluggable scripting languages, although the only one reliably included with IE besides JScript is VBScript.

As far as I have seen, there seems to be a general sort of bias toward dynamic languages in the browser, and JavaScript seems to fill this need adequately enough that network effects make any other language a non-starter. The language is actually quite powerful, though its implementation in browsers leaves much to be desired.

Jeffrey Hantin
Don't use VBScript in IE - it's some horrible variant of VB that the big MS thought would take off but didn't. It doesn't actually work like normal VB or VBScript, and it's slower that Javascript.
Keith
What is lacking in, say, WebKit's or Gecko's implementations of JavaScript/ECMAScript that is available in non-browser implementations? That comment is totally confusing to me.
eyelidlessness
+2  A: 

If you're thinking that JavaScript has deep issues, I recommend Doug Crockford's book, JavaScript: The Good Parts. (Or Google for "Crockford JavaScript" to find several video presentations he's done.) Crockford sketches out a safe subset and set of practices, and specifically lists some parts of the language to avoid.

I'm unaware of plans to replace JavaScript as the de facto means of manipulating the DOM. So best learn to use it safely and well.

Dave W. Smith
+3  A: 

Short term, I'd use things like jQuery to hide the browser incompatibilities. Long term, technologies like Silverlight or Adobe AIR may make this a very different minefield (but still a minefield) in the future.

Marc Gravell
+1  A: 

I don't think Javascript will be replaced any time soon. For a completely different approach to rich clients, you might want to investigate Flex, which is a Flash-based technology.

Flavius Stef
+3  A: 

Doug Crockford gave a talk to Google detailing the bad and good parts of JavaScript and its future. It actually hasn't changed much at all since 1999--which can be said to be a good thing (pretty much all browsers can run the same code as long as you're aware of their limitations) and Doug shows where the good parts were mostly misunderstandings that turn out to be very powerful.

For DOM manipuluation, look at JQuery as a client-side library that replaces most of the awful DOM API with operations that are a pain to write to pretty elegant bits of code that are easier to write.

sj2009
+1  A: 

Maybe something like haxe (see haxe.org) could help you. It is a language which seems cleaner than JavaScript and can be compiled down to JavaScript, so it can be run inside a browser.

I know that this is not a direct answer to your question, but I thought it might be interesting for you, nevertheless.

Karl Bartel
+1  A: 

Jquery (still javascript but) it will really help you they have support for almost all the browsers and it isn't really that hard to learn :)

Yassir
+1  A: 

If you're willing to restrict your customers/visitors to specific browsers, and possibly willing to require them to install a plug-in, you could look at MS Silverlight -- a readable overview is on wikipedia. With Silverlight 2, you can run, client-side, code you've written in C#, IronPython, IronRuby, VB.NET, etc; the free Moonlight clone of Silverlight, from the Mono project, promises to bring the same functionality to Linux.

In practice, most developers of web apps and sites prefer to reach wider audiences than Silverlight (and eventually Moonlight) can currently deliver -- which means sticking with Javascript, or possibly Flash (which uses a similar programming language, Actionscript).

So, gaining substantial mindshare, adoption and traction for anything else is proving to be an uphill fight even for Microsoft with its large groups of engineers and marketing budgets and a free-software project on the side (to possibly ease worries about proprietary lock-in) -- which may help explain why there's very little interest, e.g. on the part of the Mozilla Foundation, in pushing towards such a goal. "Apart from interoperability", you say: but clearly the issue of interoperability is THE biggie here, given what we observe wrt Silverlight's progress...

Alex Martelli
+2  A: 

As already said, you have Flash (ActionScript, which is a derived language from Javascript) and Silverlight/Moonlight (IronPython, IronRuby, JScript, VBScript, C#) that can run in the browser via plugins (the first one being much more ubiquitous).

There is also another alternative if you like Ruby: HotRuby, it's a ruby implementation in javascript that will run in the browser. It is not very mature yet, but you can have a look at it.

Alcides
+1  A: 

One thing I haven't seen mentioned (oh, I see Alcides mentioned HotRuby while I was writing and Nosredna mentioned GWT and Script#) and would like to throw out there is there are a number of implementations of [insert language]-on-JavaScript (eg. translators that allow you to convert Ruby, Python, C#, Java, Obj-J/Cappuccino [similar to Obj-C/Cocoa] or Processing [for Canvas] to JavaScript either on the client or before deployment [and some of which also feature various abstraction libraries]). Of course there's a performance overhead if it is being translated on the client, but if you are more comfortable with another language it will allow you some flexibility.

Personally, though, I recommend learning to love JavaScript. It's an excellent, powerful language, and pretty elegant once you get to know it. I'm facing the opposite dilemma, chomping at the bit to have a capable server-side JavaScript/DOM solution that meets all of my needs. /unsolicited opinion

eyelidlessness
I mentioned GWT and Script#. For those interested in Script#, the link is http://projects.nikhilk.net/ScriptSharp/
Nosredna
Thanks Nosredna, noted.
eyelidlessness
+1  A: 

Many people understand that Javascript isn't best and prettiest language ever. However, it is currently supported by browsers, and thus it will be extremely hard to introduce a different language. We simply don't need another browser war.

This explains why I know of no plans of switching to a different client-side language.

But I think Javascript isn't so bad if you start thinking about DOM model and how would one work with it. Many things that are messy with JS are the result of the way DOM model works.

ilya n.