Slashdot Mirror


Should JavaScript Get More Respect?

An anonymous reader points out an article in IBM's Crossing Borders series about the language features of JavaScript, surely the Rodney Dangerfield of scripting languages. But with increasing use in such technologies as Ajax, Apache Cocoon, ActionScript, and Rhino, some industry leaders are taking a fresh look at the language. From the article: "Nearly every Web developer has cursed JavaScript at one time or another. Until recently, many developers had all but written off JavaScript as a necessary evil at best or a toy at worst... But JavaScript is becoming increasingly important, and it remains the most broadly available scripting language for Web development."

26 of 439 comments (clear)

  1. Dense != Good by Marcus+Green · · Score: 4, Insightful

    According to the article

    "My friend and colleague Stuart Halloway, one of the foremost experts on Ajax, begins a JavaScript class with a provocative statement: "By 2011, we will recognize JavaScript as a language with a better set of features for developing modern applications." He then says that JavaScript programs are often 10 times as dense as similar Java programs and goes on to show the language features that make it so."

    The author seems to equate dense with good, not an association I make

    1. Re:Dense != Good by Anonymous Coward · · Score: 2, Insightful

      He then says that JavaScript programs are often 10 times as dense as similar Java programs

      So are the javascript developers in my experience. I kid, I kid...

      I agree with parent poster that there seems that a lot of people take lines of code as the only measure of how good a language is. Something like 80% of developer time for an average project is spent on maintenance, and often there are new developers doing it. So in my opinion clarity is at least as important.

      I admit that fewer lines of code can make code more readable, but brevity does not automatically mean clarity. Witness many perl based apps, especially those that make heavy use of regexp. I have also seen some pretty unreadable Ruby code where the programmer was clearly in love with all the clever things you can do. Metaprogramming, activerecord magic, method_missing stuff, runtime changes of objects where it was just more convenient than thinking through the model, and so on. Probably fun to write, nightmare to maintain.

    2. Re:Dense != Good by marcosdumay · · Score: 2, Insightful

      "Since developers seem to code about the same number of lines of code/statement per unit time, regardless of language. 10 times as dense means the developers are 10 times as productive. Since programmers are reasonably expensive needing 1/10th as many is a good thing."

      Maybe, but writting the program is fast. What is slow is writting a program that works.

      Now, How does Javascript helps you to wite code that works at the first try, or maintanable code, or code that is easier to debug? Well, the answer is that without sane objects, a workable type system, some rules that prohibit bad patterns of code, and most of the other things that make Java verbhose Javascript simply doesn't help you.

    3. Re:Dense != Good by dwarfking · · Score: 2, Insightful

      Of course this is a humorous post, but I have to ask, what does a namespace construct provide that you don't have with JavaScript already?

      to quote Wikipedia a namespace is an abstract container providing context for the items (names, or technical terms, or words) it holds and allows disambiguation of items having the same name (residing in different namespaces)

      Couldn't you achieve the same thing by grouping variables (or functions) as attributes of an object prototype since JavaScript allows dynamically adding variables (or functions) to objects?

      Wouldn't something like

      namespace TopLevel {
      int count = 0;
      };
      int count = 5;
      TopLevel::count = 1;
      cout << TopLevel::count << " is not " << count << eol;

      be equivalent to

      TopLevel = new function() {
      this.count = 0;
      }
      count = 5;
      TopLevel.count = 1;
      alert(' ' + TopLevel.count + ' is not ' + count);

      Now granted, a namespace usually exists only once in a running context where as a JavaScript object can have multiple instantiations, but nothing would prevent the program from only creating and using one copy of the object to simulate the same environment.

      Basically all this is syntactic sugar anyway. Object Orientation, Namespaces, Classes vs Prototypes, just different high level means of segregating data and grouping functions which are byte arrays in memory.

  2. Re:JS by Schraegstrichpunkt · · Score: 4, Insightful

    And yet you don't seem to know the difference between an embedded Java applet and integrated JavaScript code.

  3. Why the pressure ? by unity100 · · Score: 1, Insightful

    Lately it is like as if some circles are almost pressuring the developer community to pay more attention to java, javascript and affiliated stuff. Every now and then someone pops up and says something to that effect and chaos ensues.

    I just dont get why ?

    Theres something called freedom. If something is useful for developers, they like it and they use it, and they think good of it, they pay it respect. If something does not catch their attention, or they think its not to their liking, they just ignore it.

    I just dont get why are we being pressured to look into matters java, javascript. If they are respect-worthy, they will earn the respect by themselves good enough. If not, noone can make developers to respect something by propaganda or by coercion.

    1. Re:Why the pressure ? by Anonymous Coward · · Score: 1, Insightful

      Respect?

      How many web developers respect IE, relative to how many make their pages IE compatible?

      In the case of javascript, if you were developing a browser you would have to include javascript support or be marginalized. So while those developers have the choice not to implement it, realistically, they have to.

      Same with developing for Windows, working with it in some cases can be a pain in the ass. But that is where the market is. Thus programmer time can be wasted working with a beast while greener pastures are available, but not commercially viable.

      Standards can be forced on people, even if they are bad.

    2. Re:Why the pressure ? by Aqua+OS+X · · Score: 4, Insightful

      Developing interactive content for the web is a lot like building a house out of crap you find at the junk yard. None of the materials are great, you'll be forced to use a lot of jankie things you'd rather not use, and you may need to substitute sheet-rock for side panels from an '82 Corolla.

      In the case of anything involved in web development, I use tools because they're the best thing for the job. Unfortunately, "best" for web dev tools usually means "only" or "no one will be able to view your page if you develop with something else."

      Java Script / J Script is the devil. Development is a sloppy crap shoot, but we use it because it's there. It's now being used for ridiculous things that it was never really designed for.

      On one hand, web 2.0 AJAX sites are cool, on the other hand, AJAX makes me throw-up a little bit in my mouth every time I type it's name.

      --
      "Things are more moderner than before- bigger, and yet smaller- it's computers-- San Dimas High School football RULES!"
    3. Re:Why the pressure ? by Shaper_pmp · · Score: 2, Insightful

      "Java Script / J Script is the devil. Development is a sloppy crap shoot, but we use it because it's there. It's now being used for ridiculous things that it was never really designed for."

      What exactly is wrong with the javascript language? Everything you're ranting about is the fault of browser manufacturers and faulty/incomplete/deliberately broken implementations of javascript. The DOM support of various browsers sucks

      Some news: Lisp would be shit if there were three or four wildly-divergent implementations, each claiming to be "the" lisp. And especially if the dominant version was a bastardised Microsoft Lisp-alike which everyone who didn't know better coded-to.

      Javascript the language is actually quite compact, elegant and usable.

      --
      Everything in moderation, including moderation itself
  4. The language is fine, but it's got baggage by Radium+Eyes · · Score: 5, Insightful

    JavaScript/ECMAScript really is an interesting language; the way objects work takes some getting used to, but it's powerful, and definitely definitely not a toy language. It's when you bring the HTML DOM and browser inconsistencies into the equation that things start to get painful.

  5. JavaScript is wonderful by Anonymous Coward · · Score: 1, Insightful

    JavaScript is an absolutely great language marred by the fact that people can't distinguish a language from its library. When most people say "JavaScript sucks!" they are really saying "DHTML/the DOM object model/HTML/CSS sucks!".

    What I don't get is why developers use PHP, which looks like it was thrown up after a frat party. JavaScript would fill the bill as a decent language with a C-based syntax much better.

    1. Re:JavaScript is wonderful by killjoe · · Score: 3, Insightful

      To be fair you use the library as much if not more then you use the language. If I can't interact with databases, if I can't download a library that scrapes web sites, connect to SOAP services easily, authenticate against a LDAP server then no matter how beautiful the language is I can't use it.

      One lesson ruby learned early was that you don't get anywhere till you build your own version of CPAN (still the king!). Build your library, build a way to install, uninstall and upgrade your libraries smoothly and your language will take off.

      In conclusion. It's the library stupid.

      --
      evil is as evil does
  6. Like Visual Basic ... by Anonymous Coward · · Score: 2, Insightful

    ... it's not because you have to use it, that it makes it a good language.

    Only reason people are using it, is because it's the only thing that let you manipulate a web page and will work more or less for 99% of the people out on the internet. Would all browsers ship with only COBOL people would be using it. Would I have the coice between JS and let's say Python or Ruby, I wouldn't even have a look at it.

  7. Too Hard to unit test by Anonymous Coward · · Score: 3, Insightful

    javascript is too hard to unittest but most of that has to do with the web browser container . javascript is a victim of its environment.

  8. Dear god no. by el_womble · · Score: 2, Insightful

    My wish for web 3.0 is that Javascript is replaced entirely. The ONLY thing that Javascript has going for it is ubiquity (which I guess is down to its ease of implementation). Its not all Javascripts fault, in general, as in most things webby I blame Microsoft, but hte language itself seems to make everything you write look lke a dogs dinner.

    Wouldn't the web be a nicer place if you could script the browser using Ruby or Python? Can you imagine the fun you could have working with constructs like:

    @page.findById( "myID" ).each do |ajaxReturn| ... end

    The web could be beautiful. Next on my hit list is an improved HTML / CSS. Should rounding corners, or drawing shapes / shadows really be done with gif/pngs?

    --
    Scared of flying, pointy things snce 1979!
  9. Re:Security is a problem by vadim_t · · Score: 3, Insightful

    Oh, bullshit.

    No obfuscation will make it very different from what it is. A code indenter, a variable name replacement, and it'll be already understandable to pretty much any programmer.

  10. Daft story title... by Aphrika · · Score: 2, Insightful

    Respect is earned, not given. As far as I'm concerned, AJAX has given JavaScript a new lease of life. Without it, there would be no Gmail, no Google Maps, or at least not in the way we've come to admire them. When you see the fantastic stuff Google (and Windows Live for that matter) produce, XMLHTTP was the catalyst that made that possible, but all the donkey work is done by JavaScript.

    Thus I have a lot of respect for it as a client scripting language, in most cases it's the only way of getting something done in a browser.

  11. Re:JS by pla · · Score: 2, Insightful

    In this case it was easy enough to do, which meant we were providing the reports that senior management needed right away, giving us time to relax and build a proper & full scale SQL replacement.

    It strains credibility to claim that, after producing something functional, management would give you the time to replace it with something such that, "the recipients never knew when we migrated from the stop-gap to the final".

    And I don't mean that as a typical geek management-slam - If they can't tell the difference, why should they approve the team spending twice as long on the cleanup as on the prototype? Yeah, the engineers might know the difference, but the aesthetics of the underlying code rarely counts as making for a better a business case.

  12. Re:JS by orasio · · Score: 2, Insightful

    Cut the guy some slack.
    Only because Sun trademarked "Applet" it doesn't mean they invented it, or that they own it.
    An applet is a small app. More often, it's a web, client side app. Much more often, it's a "Sun Java Applet".
    In the context of this discussion, the second meaning was obvious. All of your responses were too pedant. There _are_ applets that are not "Sun Java Applets". In the context of _this_ discussion, it was clear what he was talking about.

  13. Re:It's not the best.... but it's not bad, either. by Randolpho · · Score: 2, Insightful

    It helps to actually preview your posts. Here's the fixed version: Javascript has some amazingly powerful functional features that make it rival some of the great languages. That said, it is hampered by a lack of true object orientation. There are syntactic hacks that allow you to *fake* private methods/properties and inheritance, but they are not really features of the language.

    It strikes me, however, that one of the best scripting languages out there, python, took a similar path. Once python had no object orientation, and people faked it with syntactic hacks. Then the syntax changed slightly and it was slowly added over the years, even as compatibility was kept with previous versions.

    Javascript could take such a route. It's not a bad languages; it could get better.

    --
    "Times have not become more violent. They have just become more televised."
    -Marilyn Manson
  14. Re:Disagree by arevos · · Score: 3, Insightful

    In what bizarro world do you live where having a DOM interface means "a very reach featureset"?

    I said, "As a language". Javascript's standard library is small, but the functionality the language itself supports is quite advanced. Closures, prototyping, mutable objects, and consistent OO (i.e. everything is an object), make Javascript rather flexible; just look at the additions Prototype has added in.

    Javascript has no threads, the lack of thread control structure therefore doesn't matter much.

    Ah, you're quite correct; Javascript is singled threaded. However, considering the amount of asynchronous callbacks from setTimeout, setInterval and XMLHttpRequest, one has to wonder whether the very lack of threading could not be construed as a disadvantage on its own. Since each Javascript function is axiomic, one would have to split up complex functionality to run across several functions.

    I strongly disagree: Javascript has no standard library.

    What do you mean by "Javascript"? Are you referring to the ECMAScript dialect (which, so far as I'm aware, does have a standard library), or are you using "Javascript" to mean "Any ECMAScript browser implementation" (in which case you are technically correct)?

    Regardless, the standard libraries of JScript and Javascript overlap considerably, so although you can point out, quite correctly, that ECMAScript does not define a standard library per se (so far as I am aware), from a practical standpoint the major browsers have a number of EMCAScript objects in common, which mounts to the same thing as a standard library in practise.

  15. (Browser as development platform)!=AJAX by bcrowell · · Score: 4, Insightful

    I have a hard time understanding why I hear so many people complaining about JS as a language. I think a lot of Java programmers don't like it because it's not Java (not strongly typed, ...), and a lot of C++ programmers don't like it because it's not C++.

    The truth is that you can do some pretty amazing stuff with JavaScript. My favorite demo is here. It's a web-based calculator, and if your browser has MathML set up correctly, it'll display your equation on the fly, as you type it, in standard math notation. For instance, if you type 1/(2+pi), it displays a fraction bar, with 1 on top, and 2+pi on the bottom (pi rendered as a Greek letter). (I think recent versions of Firefox have MathML and its fonts set up correctly by default, but if not, you can download the necessary fonts (instructions). For IE, you need to install MathPlayer.) What I think this calculator app demonstrates pretty dramatically is how powerful a development platform the web browser can be, without messing with the ugliness of AJAX at all. WYSIWYG mathematics typesetting is the kind of application that people used to pay $100 for ca. 1995, and now it's not only free, it's open-source, and it's an app that you can just run in your browser, without having to install anything.

  16. Re:JS by budgenator · · Score: 2, Insightful

    From what I've seen, 25, 000 lines of javascript has only one linefeed :-)

    --
    Apocalypse Cancelled, Sorry, No Ticket Refunds
  17. prototype.js by Lothar · · Score: 3, Insightful

    I have one word for all of you: "prototype.js" ( http://prototype.conio.net/ ). The day I discovered prototype.js I stopped hating javascript. It also made me appretiate the really cool ways javascript lets you do inheritance etc + reading the prototype.js code really gets you learning.

    If you also use Firebug (make sure you get the latest beta) for debugging then programming web and javascript becomes fun!

    With prototype.js the javascript code becomes probably 30-70% smaller. No self respecting javascript programmer should be without prototype.js. It rocks!

  18. Re:Needs a Concatenation Operator by Anonymous Coward · · Score: 1, Insightful
    Plenty of other mainstream languages reuse + for string concatenation (C++, C#, Java)
    That doesn't mean it's a good idea, especially for a language where conversions from strings to numbers and back are done automatically.

    In C++, string + int doesn't concatenate the int onto the string. If you're lucky it's an error. If you're not lucky, it converts the int into a character and appends that character. If it's a string literal rather than a std::string, even worse. Reusing << would have been a better choice than + in C++.

    if you're really worried, you can always declare something like: function strcat
    Which doesn't solve the grandparent's problem, because it doesn't remove the functionality from +