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."

30 of 439 comments (clear)

  1. JS by djupedal · · Score: 5, Interesting

    it remains the most broadly available scripting language for Web development.

    As someone who has written applets with over 25,000 lines, I can easily agree. Out of the roughly two dozen languages (scripting, etc.) that I know, JS has been a cornerstone of both simple and solid applets and the quick & dirty prototype. Let's hope the future agrees :)

    1. 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.

    2. Re:JS by ignavus · · Score: 4, Funny

      "25,000 lines of Javascript ? What could you possibly be doing which requires that level of Javascript interaction ?????"

      document.write('25,000 bottles of beer on the wall, 25,000 bottles of beer. Take one down and pass it around - 24,999 bottles of beer on the wall');
      document.write('24,999 bottles of beer on the wall, 24,999 bottles of beer. Take one down and pass it around - 24,998 bottles of beer on the wall');
      document.write('24,998 bottles of beer on the wall, 24,998 bottles of beer. Take one down and pass it around - 24,997 bottles of beer on the wall');

      etc ...

      --
      I am anarch of all I survey.
    3. Re:JS by HxBro · · Score: 4, Informative

      After writing javascript for the past 6 years on digital tv platforms, I can say I've seen EPG's, Games, Apps running on liberate based set-top boxes and various IPTV set-top boxes could be running apps of similar size at time too.

      Granted you do try keep the sizes down but in some cases especially and EPG you do end up writing lots of code.

    4. Re:JS by mikek3332002 · · Score: 4, Funny
      document.write('25,000 bottles of beer on the wall, 25,000 bottles of beer. Take one down and pass it around - 24,999 bottles of beer on the wall');

      A much better form for 25000 lines would be having, 12499 bottles of beer on the wall lines, an initlization statment, and a decremeant function after every write line. That way you can easily modify the code to start off with what ever number you want.
    5. Re:JS by h2g2bob · · Score: 4, Informative

      How about Mozilla firefox (or any of it's extensions).

    6. Re:JS by Anonymous Coward · · Score: 4, Funny

      Also, it's a good idea to Write and Save your JavaScript a Word document (eg in an editor like Notepad), not scrawled in Paintbrush and saved as a Bitmap File. It's funny how the Internet can't compile my Paintbrush Javascripts lol! My fried says thats how all the best programmers do it, but I can't get it work. maybe I don't get something? something vital? I think that must be it

    7. Re:JS by Anonymous Coward · · Score: 4, Funny

      My sarcasm detector exploded. ow.

    8. Re:JS by walt-sjc · · Score: 5, Funny

      25,000 lines of Javascript ? What could you possibly be doing which requires that level of Javascript interaction ?????

      1000 lines of application code, and 24,000 lines of browser compatibility code.

    9. Re:JS by CastrTroy · · Score: 4, Funny

      try{
      tellJoke();
      }
      catch(JokeException e)
      {
      printf("joke wasn't funny");
      }

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    10. Re:JS by foniksonik · · Score: 4, Informative

      How about Dreamweaver? Have you ever looked at it's WYSIWYG code? All Javascript. In fact the entire UI is 90% Javascript.... you can customize the whole app by editing, you guessed it Javascript.

      --
      A fool throws a stone into a well and a thousand sages can not remove it.
    11. Re:JS by hobo+sapiens · · Score: 4, Funny
      I only had 3 lines.
      Yeah, 3 lines and an endless loop. You meant:

      for(var i=25000;i>0;i--)
      document.write((i + ' bottles of beer on the wall,' + i + ' bottles of beer. Take one down and pass it around ' + (i-1) + ' bottles of beer on the wall\n');

      Dude, this is slashdot. You can't be posting endless loops like that, that could be dangerous! Have you any idea how many geeks will be frozen in front of their computers until they involuntarily fall asleep?
      --
      blah blah blah
  2. 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 MichaelSmith · · Score: 4, Funny
      The author seems to equate dense with good, not an association I make

      By that standard APL would be hard to beat.

    2. Re:Dense != Good by sholden · · Score: 4, Interesting

      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.

      But Javascript is no where near 10x as "dense" as Java, http://www.theadvisors.com/langcomparison.htm while flawed in many many ways puts Perl at 2.5 times as "dense" as Java. There is no way in the world that Javascript is four times as "dense" Perl...

    3. Re:Dense != Good by D-Cypell · · Score: 5, Funny

      The author seems to equate dense with good

      The irony of this is so elegantly compact I am concern a singularity may form around the vacinity of this article.

  3. Re:Why the pressure ? by tpwch · · Score: 4, Informative

    Java and Javascript? Why would anyone do that, since those two are not related other than the name. Sun developed Java, and Netscape developed Javascript. Totally independent of each other. I'm starting to get tired of people thinking that they have something to do with each other.

    --
    Posted by a Debian GNU/Linux user
  4. Re:Yes, but Javascript is a bad language. by Myen · · Score: 4, Informative
    Every function has a variable number of arguments. You can access it via the keyword arguments - it's an array. So yes.

    function foo() {
      alert(arguments[0])
    }
  5. I love the autopointerage & hate the scope iss by cyclomedia · · Score: 5, Informative
    Would be nice to have everything my way, the sheer built in extensibility of the language is in my opinion nothing short of beautiful, and something other languages could do well to imitate (check out D, for example).

    allow me to elaborate, suppose you want to know if the version of the language on your platform supports an intrinsic array push function, and if not, attatch your own:

    if( !Array.push )
      Array.prototype.push = function( item ){ ... }
    firstly the reference to .push in the if has no brackets, so it becomes a pointer to the function within the intrinsic Array class. you can then create a function and assign it to that pointer. Sheer magic and gorgeously intuitive.

    sticking with arrays you can grow and shrink them with little to zero fuss:

    function array_push( arr , item )
      arr[arr.length] = item;
    magically the array is one index longer. you can just set arr.length and it will append or delete indexes for you.

    you can also use this to assign functions to other object's handlers, most notibly events

    someObject.onclick = myFunction
    But this has brought up the thing that really really needs fixing, suppose i want that onclick function to pass some info to myFunction when i call it i have to do this

    someObject.onclick = function(){ myFunction( this.someAttribute ) }
    so instead i've created a function inline to hold my custom function, firstly it's not immediatley obvious to what object the "this" applies. if i'm running this code in a class does the this mean the class or someObject, one hopes it means the someObject.

    next is the scope issue i've talked about suppose i'm dynamically creating objects on the fly and want the callback to reflect the id thus

    for( i=0 ; i<10 ; i++ )
    {
      someObject[i] = new SomeObject();
      someObject[i].onclick = function(){ myFunction( i ) }
    }
    every single object will pass the value of 10 to myFunction, because after the function has finished the instance of i in memory that was used is still sat there and every myFunction has been given a pointer to it, not the value it was when it was initialised!

    so some oversights still exist, if only there were ways you could explicitly state "pointer to" or "value of" like in, oh, every other language including visual basic
    --
    If you don't risk failure you don't risk success.
  6. 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.

  7. Re:Yes, but Javascript is a bad language. by masklinn · · Score: 4, Informative

    It is not possible to have two methods with the same name and different parameters (only one of those will ever be called).

    Because Javascript has no ways of dispatching: all functions (remember that Javascript methods are exactly like functions) use varags, and the arguments you ask for are but pointers to vararg cells.

    Example:

    1. function foo(a, b, c) {
    2. return [a, b, c, arguments]; // `arguments` holds every single argument of your function no matter what
    3. }
    4. foo() // -> [null, null, null, []]
    5. foo(1) // -> [1, null, null, [1]]
    6. foo("foo","bar","baz","buzz","bon") // -> ["foo","bar","baz",["foo","bar","baz","buzz","bon" ]]

    On the other hand methods behave like objects. One can have arrays of methods and then call mymethods[2](param);!

    It's not that JS functions "behave" like objects, JS function are objects, period. Callable objects maybe, but objects nonetheless, they're no different from strings, integers or lists in that aspect.

    And this is one of the nicest features of the language (along with lexical scoping and complete closures)

    --
    "The way we can tell it's C# instead of Haskell is because it's nine lines instead of two." -- wadler
  8. 25000 lines: by hummassa · · Score: 4, Funny

    Any serious Ajax application.

    --
    It's better to be the foot on the boot than the face on the pavement. ~~ tkx Kadin2048
  9. Re:I love the autopointerage & hate the scope by Shano · · Score: 4, Informative

    That isn't really an oversight, it's the way closures work. Most functional languages let you create closures explicitly so the problem doesn't arise. Javascript does it automatically, and usually when you don't expect it. In Javascript, you can do:

    someObject[i].onClick = function(i) { return function() { myFunction(i) } } (i);

    That creates a closure for each handler, with its own copy of i, so they will all get the values you want. I have no doubt there are other ways to do it, but this works for me.

  10. JS is not the problem, the whole environment is. by master_p · · Score: 4, Interesting

    Javascript is a fine language with elements from functional and object-oriented programming. The problem with web development is the whole environment:

    1) the coupling of the UI with the code that actually does stuff.
    2) the non-efficient and error-prone methods of communication between client and server.
    3) the non-existent security regarding JS code; anyone can see it.
    4) the mixing of a tagged document language with a programming language.

    Ideally, web applications should only consist of source code in one language which is clever enough to be able to provide all the necessary abstractions. In reality, such a language does not yet exist, making web applications development 10 times more difficult than what they should be: the minimum number of languages to use for a web app is 5: 1) html, 2) css, 3) javascript, 4) java/php/ruby/python/perl/whatever, 5) XML...and let's not count the various XML schemas required for various domains of the back end, because the number of 'languages' one needs to know will grow exponentially!

  11. 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!"
  12. Re:JS is not the problem, the whole environment is by AlXtreme · · Score: 4, Interesting
    3) the non-existent security regarding JS code; anyone can see it.
    Repeat after me: Obscurity is not the same as Security

    If you are sending information to the browser that you don't want to be known, then you're doing something wrong. This is the case for JS, as well as for AJAX, Flash or Java applets. Or client-side code in general.

    Seriously, I've seen students faces turn white when I mention that I could log into and mess up their remote SQL database, thanks to them putting their (administrator!) username/password combinations in client-side Java bytecode. They would then try to obscure their passwords somehow, which leads to an arms-race with other teams trying to break in. Security can be loads of fun!

    --
    This sig is intentionally left blank
  13. Server-side JavaScript by sveinb · · Score: 5, Interesting

    I've been using PHP and Perl server-side and, reluctantly, JavaScript client-side for years before I actually bothered learning JavaScript. When I finally did, I discovered a language which was similar to PHP and Perl in that it supported most, if not all of their language constructs and which in many ways was more elegant (IMHO). So my dream was to use JavaScript both server- and clientside. That can be done in .net/mono, I guess, but I prefer the lightweight nature of PHP, Perl, Python etc. So I started http://www.sf.net/projects/jsext - check it out! The plan is to support C libraries (done on Linux, Windows version under construction) and Python modules (not done). There are other, similar projects, too: http://en.wikipedia.org/wiki/Server-side_JavaScrip t

  14. Needs a Concatenation Operator by ajs318 · · Score: 4, Interesting

    JavaScript has one really, really nasty flaw. It "recycles" the + operator (which usually is used for adding numbers) to concatenate strings. In some languages (e.g. BASIC), which treat numbers and strings as distinct data types, this is not a problem. But JavaScript is dynamically-typed -- in other words, you don't have to tell it what is a number and what is a string; it tries to work that out for itself. And this is the source of the error. When you innocently write
    document.theform.hours.value += 1;
    in a bit of form-munging code, what happens is that a figure "1" gets appended onto the end of the value in the "hours" box. If you want to increment it by one, you have to use something like
    document.theform.hours.value -= -1;
    which is mathematically sound, but looks very weird.

    JavaScript really needs a dedicated string concatenation operator, in recognition of the fact that numeric addition and string concatenation are different operations. Unfortunately, the "dot", which would be the most obvious choice as it's already used for the concatenation operator in other languages, is already very much in use -- not to mention that changing an operator in this fashion is likely to break things. And the breakage will be even worse than register_globals in PHP, since JavaScript runs on the client side -- meaning no webmaster can ever know for sure what JavaScript engine is in use.

    --
    Je fume. Tu fumes. Nous fûmes!
  15. Personally I think it's a pretty cool language by CTho9305 · · Score: 4, Interesting

    You can do some pretty fun things with it, such as a true 3d engine, a raytracer, games (careful, robots is addicting!), out-of-order CPU simulators, and other stupid things without any plugins - all the user needs is a halfway decent browser.

  16. (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.