Is Javascript code always so full of bugs?

Slightly off topic… The “debugging options” got turned on in my browser recently. I think this happened when I was debugging some web code in Visual Studio.

From this, it’s been interesting to see how regularly my web browsing experience is now interrupted by what must surely be outright bugs in Javascript code. Very often these are null object errors. I’ve always been more than sceptical about Javascript as a language for writing reliable, correct, reusable, efficient code (something F# is obviously good at – and yes, you can compile it to Javascript). But is this kind of bug really the new black? 

Separately, I’ve noticed an extremely disturbing increase in the number of “this web page is not responding” errors. A good time for those working on automated termination proofs to apply their talents to termination of Javascript code…

What really surprises me is that basic code correctness issues such as programming-without-the-curse-of-nulls do not seem to feature on the minds of those on the Lang.NEXT panel. I guess that when your language doesn’t control nulls, you don’t think its a problem.


Comments (11)

  1. TejasJ says:

    I agree with this problem

  2. Ivan says:

    Dear Don, if you have a little self respect, than you would do better if you change your browser. I browse with Firefox and I rarely stumble upon any javascript errors (I can see them in the error log). And when I do this is from the fact that someone has written his/her code without testing it if it works in all browsers. So please be kind and don't blame the language.

    [ Don says: I really don't agree with blaming the browser… The errors above are nearly all basic things that would be prevented in a strongly-typed language (missing identifiers, undefined variables), or null errors that would have likely been prevented if the code was authored in a language such as F# that greatly restricts the use of null values.

    The behaviour of JS code may be sensitive to which browser, but all of these errors were in consumer-facing web applications – including one online banking application. These should execute reliably on all major browsers, and it should be possible to reliably author such applications without such basic errors. ]

  3. ildjarn says:

    Is it really a surprise that web developers tend to write less robust code? I don't think Javascript is to blame here..

    [ Don says: Sorry, I really don't agree with that…. nearly all of the errors shown above are basic things that would be prevented in a strongly-typed language (missing identifiers, undefined variables), or null errors that would have likely been prevented in a language such as F# that greatly restricts the use of null values ]

  4. ildjarn says:

    Maybe the language could help more than it does (I'm a HUGE fan of F#, don't get me wrong), but when any language is targeted almost exclusively at unskilled developers, poor code is bound to be the result.

    Would that same unskilled demographic endure the 'tedium' of fixing compiler errors in a strongly, statically-typed language? Personally, I suspect they would instead just jump ship to an 'easier' language (why do you think PHP is so popular?).

  5. Jens says:

    A language which didn´t works correct in all browsers isn´t a language.

    That´s the problem. Point

  6. I challenged readers to do this same experiment a few years back for the same reason…/Return-of-the-Smart-Client.aspx . Of course, my predictions may not have turned out so well…

  7. Onorio Catenacci says:

    I saw this so often that I just shut off the display of those JS errors.  I can't believe all those coders could be that sloppy so I figured it was because of different conformance to the JS "standard" by various browsers.

  8. Mephux says:

    Don, can you post more on the errors please? This dialogs are not very detailed and could be misleading. I.E console undefined is standard is Safari,Chrome,Opera and Firefox. $ undefined is likely jQuery, prototype or so other framework. Thank you.

  9. wilbur4321 says:

    I think that's ildjarn's point.  Web developer languages like javascript have taken off because they are so "fast" and "easy" to work with.  A better language stops a lot of these bugs in their tracks by forcing you to deal with the possibilities — which is "harder" and "less efficient".  It's like the old VB — getting an app that appears to work was a lot easier than other languages at the time; getting an app that worked reliably was at least as hard, if not harder.

  10. Jason Mulligan says:

    Don, the authors of the code are to blame. Yes, a statically typed language would expose the error(s), but so does "use strict";.

    [ Don says: I doubt "use strict" would have fixed the errors above. And not the null-reference errors, of course. ]

  11. Mark says:

    Don, I agree with you. I think it's perfectly understandable to have a language like javascript for unskilled, non-professional developers to use. But why punish professional developers who are willing to write good code by not providing a strong typed language as an alternative standard… I just don't understand.

    Personally, I love F# and Silverlight!!!