Web 2.0, Meet JavaScript 2.0 248
Jeremy Martin writes "Well I suppose it's an undeniable fact about us programmer-types — every now and then we just can't help but get excited about something really nerdy. For me right now, that is definitely JavaScript 2.0. I was just taking a look at the proposed specifications and I am really, truly excited about what we have coming."
Ugh (Score:5, Insightful)
Operator overloading? Great, now you can enjoy C++ style code, where left shift and print are the same command.
All of the proposed changes are a step backwards. JavaScript is currently a language with great, clean, semantics and slightly ugly syntax. They want to make the semantics less clean and the syntax even more horrendous.
Cross-Browser (Score:3, Insightful)
JavaScript changing into Java (Score:5, Insightful)
Javascript 2.0, usable by 2015... (Score:5, Insightful)
By the time JavaScript 2.0 is available in nearly all browsers you find in the wild, there will already be a JavaScipt 4.0 spec out and you'll be able to write this exact comment with the dates and browser versions updated.
The point being that client-side programming is a complete mess right now. Instead of new versions of scripting languages, we should be pushing browser makers to allow scripting to be installed via plug-ins rather than being native to the browser. That way, a website can trigger the user to update to the latest version of the language spec (ala the much-maligned-here flash plugin). That should also allow website authors to use any language, not just JavaScript. After all, if you're developing your site in RoR, wouldn't it be easier to use Ruby for the client-side scripting as well as the server-side? The same would go for Python, Perl, PHP (/me shudders) or even Java/Groovy.
But as long as we are beholden to the browser manufacturers to release updates of their browsers in a timely and compliant manner, we'll be stuck in this cycle where we can't use the latest-and-greatest features until they're no longer latest-and-greatest.
Is writing Evil Javascript still supported? (Score:3, Insightful)
Yes, I'm aware of NoScript and similar add-ons, and I'm happily using them. That helps, but there's still too much bad and ugly stuff out there to be happy about anything good that JS can do.
Re:v2.0 (Score:5, Insightful)
I can. Javascript makes it really quick to hack together a dynamic page. Sure, it results in spaghetti code and the resulting HTML tends to be out of standard, but people will keep using Javascript as long as it remains so damn easy.
Re:v2.0 (Score:5, Insightful)
Re:Ugh (Score:3, Insightful)
Re:why won't javascript die already? (Score:1, Insightful)
Time for a slashdot car analogy.
On the roads, we have motorbikes, cars and 18 wheeler trucks. I don't care which one we all use, as long as we eliminate 2. I'm tired of the inconsistency.
The fact of the matter is SQL would suck at manipulating the dom on the client. Javascript would suck as a language to query a database. Server side scripting (php, python etc) could be hacked to natively query a database or manipulate the browsers dom, but it would be ugly AND require support from every browser. I hardly think IE is likely to natively support python.
We have different tools for different jobs, this is for a reason.
Re:v2.0 (Score:2, Insightful)
Re:Ugh (Score:5, Insightful)
Grand-parent gave an example of built-in operator overloading, not user-defined operator overloading. So no, it isn't "obvious" that he means user-defined operator overloading.
From the linked-to article:
Features that are guaranteed to be misused should be eliminated.
What a load of utter bollocks! Show me a feature that cannot be misused, and I'll show you a feature that isn't terribly useful.
If you dont know the difference between a group, a ring, and a field, you have no business overloading operators.
What an arrogant asshole! That's as non-sensical as an assertion that only parents have any business creating class hierarchies.
Re:Ugh (Score:5, Insightful)
I do agree with you there -- we don't need classes. And if we did, we could implement them, in JavaScript.
If you really, really want to, then yes. But that it can be abused doesn't strike me as a serious reason for not including it.
I had a problem awhile ago. It was developing for HD-DVD, meaning we didn't have full JavaScript -- meaning I couldn't, say, extend Array. Even if I could, I'm not sure how much better I could make this... I had created a control for displaying a scrolling menu of widgets of some kind. The point is, the control itself shouldn't care about what those widgets are, or even that it's operating on something that's actually an array. It would've been nice to let it work with an array for now, knowing I could always roll something that pretends to be an array later.
Instead, what I ended up doing was wrapping the Array in a monstrosity which contained methods like getValue(), setValue(), etc. It was hideously ugly, but it would tend to work, and would even automatically wrap an Array if needed.
But it's ugly hacks like that which drove me away from Java in the first place. I'd rather duck-type it properly, like I do in Ruby. If it claims to have a working [] operator, and has methods like size() or length(), either it's an array, or it's pretending to be one, so treat it like an array.
Re:"Program Units" - potential for misuse (Score:3, Insightful)
Re:v2.0 (Score:4, Insightful)
Re:I'm actually not looking forward to this (Score:5, Insightful)
JavaScript is a language with first-class closures and a rich Self-style object model. The syntax is a bit ugly, but the language is really a joy to work with once you get past the 'it looks like Java' stage.
class keyword (Score:3, Insightful)
Re:v2.0 (Score:3, Insightful)
Given that your main objection to JavaScript seems to be that you refuse to learn the paradigms it espouses, I think that's plenty of evidence right there. Just because you don't understand a language does not make it weak.
Re:v2.0 (Score:4, Insightful)
"On a scale of 1 to 10, how would you rate yourself with Javascript?"
"I'd say about an 8."
"Okay, can you write a simple Javascript object on the whiteboard for me?"
"..."
Lucky for them, I mostly looking for smart people I can train. I've only met one other person IRL who even knew how to code Javascript properly.
Funny, my Javascript tends to be well structured, object oriented, and reusable.
The #1 problem with Javascript is that everyone "learned" it from cutesy little toolbar/cursor scripts rather than actually learning the language. As a result, it's not immediately obvious to most coders how to use the language. Thus they tend to run into variant typing issues and write a procedural mess of spaghetti code. Which is silly, because Javascript has some of the best features of functional languages like LISP!
Netscape published an excellent guide to the language [mozilla.org] over a decade ago (now maintained by Mozilla.org). I'm going to take a wild guess and say... you've never read it, have you? If you had, you might be bemoaning the lack of good Javascript knowledge in the market rather than placing blame on the language itself.
Re:v2.0 (Score:1, Insightful)
Javascript is a "real language". If you were as good of a coder as you claim to be, you never would have made such a silly statement.
Here's the link to the real info. (Score:3, Insightful)
First, ignore the ad for the blog and go directly to the language specification. [ecmascript.org]
I read through that and winced. It's one of those backwards compatible hacks that makes a language ugly. Current Javascript has a class implementation based on copying a base object, but no real class abstraction. This follows the model in Self. Most other object oriented languages (C++, Python, Java) have explicit class declarations. Javascript 2.0 adds class declarations without throwing out the old mechanism. This is a mess. I understand why they were forced to that decision, but it's still a mess.
The trend continues. They threw in most of the things Python 3K has and current Javascript doesn't: type annotations, generators, and packages, and namespaces. There's type checking, but it's optional for now. (This is like the transition from K&R C to ANSI C). Java-type interfaces where thrown in. At least they didn't add templates. It's a collection of features in search of a design.
In the end, we get something that's like a mixture of Java and Python.
Re:v2.0 (Score:4, Insightful)
Insightful? What? In the old days of the web the whole javascript / dynamic html nonsense was a mess. But modern javascript/html interaction is much more sensible.
It might surprise you to learn this but javascript is actually quite a nice language -- I'm a Real Programmer(TM) and I've been dabbling with a bit of javascript recently for UIs to our tooling -- and the only thing dragging it down is DOM's uglyness (and, frankly, life's too short to try to learn the stupid inconsistencies between Firefox, Safari and IE). However there are solutions: a library called jQuery makes working with the browser rediculously easy: it abstracts away various inconsistencies for you (and also makes the syntax nice and elegant/compact).
A nice example is setting CSS properties - with jQuery you simply use: $("p.showable").css("font-weight", "bold").show("slow"); this code selects all paragraphs with the "showable" class, makes their contents bold and fades them into view (if they're not already visible)
Debugging isn't as bad as you'd think, either thanks to Firebug. And AJAXy things can make a page much more useful - we update a log viewer based on the restrictions specified (eg. from machine X,Y or Z, from application B, log level >= INFO) which makes it at least as useful as ssh+tail :-)
Re:v2.0 (Score:4, Insightful)
So I've been trying to wrap my head around this statement. I'm not too sure what it means. Am I supposed to be angry at javascript because it's ease of use causes terrible code to appear in the world because Joe Sixpack thought he was a js coder by looking up examples in the internet? Or is it more of an elitist coder mentality, like a secret javascript club where Joe Sixpack should not be allowed in?
Re:Examples of CPU-sucking Javascript (Score:3, Insightful)
Re:v2.0 (Score:3, Insightful)
Like HTML (and unlike XHTML), Javascript tries to limp along as much as possible when it encounters ambiguous code. So the expression "You collected " + bugs + " bugs.", where bugs is an integer, will turn bugs into a string and concatenate the strings. In C, adding an integer to a character will increase the ASCII value of the character by the amount of the integer ('a'+5 -> 'f'), so we can see that adding integers and strings is an ambiguous and therefore error-prone process. Tons of websites, even high-profile ones, have lots of errors in their Javascript passing silently, and they work anyway.
Given how the Web works, that's probably the right decision for Javascript. It fits with the idea of graceful degradation. You shouldn't be angry at Javascript at all. But this leniency does mean that just because a script runs, doesn't mean it's not full of errors. And just because you can build a website that uses client-side Javascript, doesn't mean you know the language well enough to build a reliable server-side app in it.
But given that history of C#, Java, C++, and any other popular programming language, I disagree that the leniency in Javascript's spec is the main cause of the low signal-to-noise ratio in Javascript programmers. Really, I think it's just because everyone has access to a Javascript interpreter in their browser, and disciplined programmers are a tiny subset of "everyone."