tags:

views:

852

answers:

15

Would it not make sense to support a set of languages (Java, Python, Ruby, etc.) by way of a standardized virtual machine hosted in the browser rather than requiring the use of a specialized language -- really, a specialized paradigm -- for client scripting only?

I understand the pragmatic issue that JavaScript is simply what we have to work with now due to evolutionary reasons. I'm thinking more about the long term. With regard to backward compatibility, there's no reason that JavaScript could not be one of the languages supported by this browser virtual machine.

+9  A: 

Yeah javascript is cool if you get a helper library like Prototype (prototypejs.org) or jQuery (jquery.com). Check them out. Alternatively there is flash or silverlight ;)

Per Hornshøj-Schierbeck
+6  A: 

Well, yes. Certainly if we had a time machine, going back and ensuring a lot of the Javascript features were designed differently would be a major passtime (that, and ensuring the people who designed IE's CSS engine never went into IT). But it's not going to happen, and we're stuck with it now.

I suspect, in time, it will become the "Machine language" for the web, with other better designed languages and APIs compile down to it (and cater for different runtime engine foibles).

I don't think, however, any of these "better designed languages" will be Java, Python or Ruby. Javascript is, despite the ability to be used elsewhere, a Web application scripting language. Given that use case, we can do better than any of those languages.

Adam Wright
+1 for your great comment on IE's CSS team... ;)
Steve Harrison
-1 for the IE CSS team remark. IE6 wasn't bad when it was released, it's main competitor was the buggiest piece of crap software that has ever been written. Person attacks, although somtimes fun, don't make the world a better place.
erikkallen
Couldn't disagree with your assessment of JavaScript as "...a Web application scripting language..." less. It's a great, flexible language with a lot more applicability than that.
T.J. Crowder
A: 

Probably, but to do so we'd need to get the major browsers to support them. IE support would be the hardest to get. JavaScript is used because it is the only thing you can count on being available.

Jeff Olhoeft
A: 

JavaScript is your only native, standard option available. If you want lots of power, grab jQuery, but if you need to do a bunch more, consider writing an addon for Firefox? or similar for IE etc.

scunliffe
+1  A: 

I think this is not so easy issue. We can say that we're stuck with JS, but is it really so bad with jQuery, Prototype, scriptaculous, MooTools, and all fantastic libraries?

Remember, JS is lightweight, even more so with V8, TraceMonkey, SquirrelFish - new Javascript engines used in modern browsers.

It is also proved - yeah, we know it has problems, but we have lots of these sorted out, like early security problems. Imaging allowing your browser to run Ruby code, or anything else. Security sandbox would have to be done for scratch. And you know what? Python folks already failed two times at it.

I think Javascript is going to be revised and improved over time, just like HTML and CSS is. The process may be long, but not everything is possible in this world.

phjr
+12  A: 

If you feel like you are getting your hands dirty, then you have either been brainwashed, or are still feeling the after affects of the "DHTML years". JavaScript is very powerful, and is suited well for its purpose, which is to script interactivity client side. This is why JavaScript 2.0 got such a bad rap. I mean, why packages, interfaces, classes, and the like, when those are clearly aspects of server-side languages. JavaScript is just fine as a prototype-based language, without being full-blown object oriented.

If there is a lack of seamlessness to your applications because the server-side and client-side are not communicating well, then you might want to reconsider how you architect your applications. I have worked with extremely robust Web sites and Web applications, and I have never once said, "Hmm, I really wish JavaScript could do (xyz)." If it could do that, then it wouldn't be JavaScript -- it would be ActionScript or AIR or Silverlight. I don't need that, and neither do most developers. Those are nice technologies, but they try to solve a problem with a technology, not a... well, a solution.

hal10001
How can you say, that JavaScript isn't full-blown object oriented? It's certainly one of the most object-oriented languages that I know of. Everything in JavaScript is an object - even functions. It's just that OOP in JavaScript doesn't look like OOP in many other languages.
Rene Saarsoo
OOP is not inherent to JavaScript. You don't have packages, interfaces, abstract classes, or method overloading built into the core, and you can't extend an object -- only an object's prototype, which makes it technically prototype-based, not OOP based.
hal10001
Dead wrong on that one. "Protype" is a Design Pattern (Gamma et. al., pp 117 - 126). As you'll recall Design Patterns revolve around common designs in Object Oriented Programming. And just because the language doesn't have the same features as other OOP languages doesn't mean it isn't OOP.
Dustman
That would not make me "dead wrong", and it would simply open up the strict definition of OOP to interpretation - e.g. - how much of JavaScript is OO based. My answer: "Some of it - the rest is prototype based."
hal10001
A: 

Realistically, Javascript is the only language that any browsers will use for a long time, so while it would be very nice to use other languages, I can't see it happening.

This "standardised VM" you talk of would be very large and would need to be adopted by all major browsers, and most sites would just continue using Javascript anyway since it's more suited to websites than many other browsers.

You would have to sandbox each programming language in this VM and reduce the amount of access each language has to the system, requiring a lot of changes in the languages and removal or reimplementation of many features. Whereas Javascript already has this in mind, and has done a for a long time.

HappySmileMan
+2  A: 

While Javascript is the only well-supported scripting language you can control the page directly from, Flash has some very nice features for bigger programs. Lately it has a JIT and can also generate bytecode on the fly (check out runtime expression evaluation for an example where they use flash to compile user-input math expressions all the way to native binary). The Haxe language gives you static typing with inference and with the bytecode generation abilities you could implement almost any runtime system of your choice.

jjrv
A: 

So what you'd have done with all those Pythons and Rubys in the browser?!

1). Still writing scripted client-side apps? Well, this is nicely done with JavaScript.

2). Writing client-server apps using sockets? Why don't write them just without browser?

3). Writing standalone apps? Just do it as you do now.

Thevs
+5  A: 

How do you define best? Best for the browser, or best for the developer? (Plus ECMAScript is different than Javascript, but that is a technicality.)

I find that JavaScript can be powerful and elegant at the same time. Unfortunately most developers I have met treat it like a necessary evil instead of a real programming language.

Some of the features I enjoy are:

  • treating functions as first class citizens
  • being able to add and remove functions to any object at any time (not useful much but mind blowing when it is)
  • it is a dynamic language.

It's fun to deal with and it is established. Enjoy it while it is around because while it may not be the "best" for client scripting it is certainly pleasant.

I do agree it is frustrating when making dynamic pages because of browser incompatibilities, but that can be mitigated by UI libraries. That should not be held against JavaScript itself anymore than Swing should be held against Java.

Rontologist
+1  A: 

On Windows, you can register other languages with the Scripting Host and have them available to IE. For example VBScript is supported out of the box (though it has never gained much popularity as it is for most purposes even worse than JavaScript).

The Python win32 extensions allowed one to add Python to IE like this quite easily, but it wasn't really a good idea as Python is quite difficult to sandbox: many language features expose enough implementation hooks to allow a supposedly-restricted application to break out.

It is a problem in general that the more complexity you add to a net-facing application like the browser, the greater likelihood of security problems. A bunch of new languages would certainly fit that description, and these are new languages that are also still developing fast.

JavaScript is an ugly language, but through careful use of a selective subset of features, and support from suitable object libraries, it can generally be made fairly tolerable. It seems incremental, practical additions to JavaScript are the only way web scripting is likely to move on.

bobince
+2  A: 

The vast majority of the devs I've spoken to about ECMAScript et. al. end up admitting that the problem isn't the scripting language, it's the ridiculous HTML DOM that it exposes. Conflating the DOM and the scripting language is a common source of pain and frustration regarding ECMAScript. Also, don't forget, IIS can use JScript for server-side scripting, and things like Rhino allow you to build free-standing apps in ECMAScript. Try working in one of these environments with ECMAScript for a while, and see if your opinion changes.

This kind of despair has been going around for some time. I'd suggest you edit this to include, or repost with, specific issues. You may be pleasantly surprised by some of the relief you get.

A old site, but still a great place to start: Douglas Crockford's site.

Dustman
+3  A: 

IMO, JavaScript, the language, is not the problem. JavaScript is actually quite an expressive and powerful language. I think it gets a bad rep because it's not got classical OO features, but for me the more I go with the prototypal groove, the more I like it.

The problem as I see it is the flaky and inconsistent implementations across the many browsers we are forced to support on the web. JavaScript libraries like jQuery go a long way towards mitigating that dirty feeling.

Andrew Hedges
A: 

Well, we have already VBScript, don't we? Wait, only IE supports it!
Same for your nice idea of VM. What if I script my page using Lua, and your browser doesn't have the parser to convert it to bytecode? Of course, we could imagine a script tag accepting a file of bytecode, that even would be quite efficient.
But experience shows it is hard to bring something new to the Web: it would take years to adopt a radical new change like this. How many browsers support SVG or CSS3?

Beside, I don't see what you find "dirty" in JS. It can be ugly if coded by amateurs, propagating bad practice copied elsewhere, but masters shown it can be an elegant language too. A bit like Perl: often looks like an obfuscated language, but can be made perfectly readable.

PhiLho
A: 

I don't think you "understand the pragmatic issue that JavaScript is simply what we have to work with now". Actually it is very powerful language. You had your Java applet in browser for years, and where is it now?

Anyhow, you don't need to "get dirty" to work on client. For example, try GWT.

Marko Dumic