I've been troubleshooting a bit of JavaScript lately, so I've enabled script debugging in IE7. Whenever the browser encounters a JavaScript error on a web page, instead of the default, unobtrusive little status bar notification..
.. I now get one of these glaring, modal error debug notification dialogs:
I left this setting enabled out of pure forgetfulness. Browsing the web this way, I quickly realized that the web is full of JavaScript errors. You can barely click through three links before encountering a JavaScript error of one kind or another. Often they come in pairs, triplets, sometimes dozens of them. It's nearly impossible to navigate the web with JavaScript error notification enabled.
JavaScript errors are so pervasive, in fact, that it's easy to understand why IE demotes them to nearly invisible statusbar elements. If they didn't, nobody would be able to browse the web without getting notified to death. Firefox goes even further: there's no visible UI whatsoever for any JavaScript errors on the current web page. You have to open the Tools | Error Console dialog to see them.
The upshot of this is that JavaScript errors, unless they result in obvious functional problems, tend to go unnoticed. Things that would cause showstopping compiler errors in any other language are at worst minor inconveniences in JavaScript. When errors are ignored by default, what you end up with is an incredibly tolerant, extremely permissive programming ecosystem. If it works, it works, errors be damned.
But this unparallelled flexibility has its price. Just ask Dave Murdock, who found out the hard way how flexible JavaScript can be.
So I dug into the code, which I hadn't written, and I saw JavaScript similar to this in the execution path that was causing Firefox to hang:
var startIndex = 0; for (i = startIndex; i < endIndex; i++) { // do some stuff here }This works fine in Internet Explorer 7. What happens in Firefox? i is reinitialized to startIndex after every run of the loop. You have to declare the loop like this for it to work:
var startIndex = 0; for (var i = startIndex; i < endIndex; i++) { // do some stuff here }Putting the var before i is the way it ought to be as far as I can tell, but both Internet Explorer and Firefox do the wrong thing by developers here. Both browsers should be sticklers about requiring var in a loop variable declaration and produce a clear JavaScript interpreter error before the code has the chance to run.
It's not just JavaScript. HTML and CSS are incredibly forgiving of errors as well. Ned Batchelder observed bizarrely tolerant behavor when specifying named colors that don't exist. Consider this small snippet of HTML:
<font color='red'>█ This is RED</font>
As you vary the named color, you don't get the error you might expect. What you do get is weird colors:
| Firefox | IE7 | Opera | |
|---|---|---|---|
| red | â–ˆ #ff0000 | â–ˆ #ff0000 | â–ˆ #ff0000 |
| seagreen | â–ˆ #2e8b57 | â–ˆ #2e8b57 | â–ˆ #2e8b57 |
| sea green | â–ˆ #0e00ee | â–ˆ #0e00ee | â–ˆ #0ea00e |
| sxbxxsreen | â–ˆ #0000e0 | â–ˆ #0000e0 | â–ˆ #00b000 |
| sxbxxsree | â–ˆ #00000e | â–ˆ #0b00ee | â–ˆ #00b000 |
| sxbxxsrn | â–ˆ #000000 | â–ˆ #0b0000 | â–ˆ #00b000 |
| sxbxeen | â–ˆ #000e00 | â–ˆ #0bee00 | â–ˆ #00b0ee |
| sreen | â–ˆ #00ee00 | â–ˆ #00ee00 | â–ˆ #00ee00 |
| ffff00 | â–ˆ #ffff00 | â–ˆ #ffff00 | â–ˆ #ffff00 |
| xf8000 | â–ˆ #0f8000 | â–ˆ #0f8000 | â–ˆ #0f8000 |
(If you're curious how "sea green" can possibly equate to blue, the answers are in the comments to Ned's post.)
I can't think of any other programming environment that goes to such lengths to avoid presenting error messages, that tries so hard to make broken code work, at least a little. Although there was a push to tighten up HTML into the much more strictly enforced XHTML, it's an utter failure. If you're not convinced, read Mark Pilgrim's thought experiment:
Imagine that you posted a long rant about how [strict XHTML validation] is the way the world should work, that clients should be the gatekeepers of wellformedness, and strictly reject any invalid XML that comes their way. You click ‘Publish', you double-check that your page validates, and you merrily close your laptop and get on with your life.A few hours later, you start getting email from your readers that your site is broken. Some of them are nice enough to include a URL, others simply scream at you incoherently and tell you that you suck. (This part of the thought experiment should not be terribly difficult to imagine either, for anyone who has ever dealt with end-user bug reports.) You test the page, and lo and behold, they are correct: the page that you so happily and validly authored is now not well-formed, and it not showing up at all in any browser. You try validating the page with a third-party validator service, only to discover that it gives you an error message you've never seen before and that you don't understand.
Unfortunately, the Draconians won: when rendering as strict XHTML, any error in your page results in a page that not only doesn't render, but also presents a nasty error message to users.
They may not have realized it at the time, but the Draconians inadvertently destroyed the future of XHTML with this single, irrevocable decision.
The lesson here, it seems to me, is that forgiveness by default is absolutely required for the kind of large-scale, worldwide adoption that the web enjoys.
The permissive, flexible tolerance designed into HTML and JavaScript is alien to programmers who grew up being regularly flagellated by their compiler for the tiniest of mistakes. Some of us were punished so much so that we actually started to like it. We point and laugh at the all the awful HTML and JavaScript on the web that barely functions. We scratch our heads and wonder why the browser can't give us the punishment we so richly deserve for our terrible, terrible mistakes.
Even though programmers have learned to like draconian strictness, forgiveness by default is what works. It's here to stay. We should learn to love our beautiful soup instead.
Hows the old saying go? "Be conservative in what you do, be liberal in what you accept from others"? I think that applies here as well as it does to any programming.
mgroves on April 28, 2007 9:01 AMI recommend reading all three of Mark Pilgrim's posts on this topic, because it will inform your error handling strategies in your own applications:
http://diveintomark.org/archives/2004/01/14/thought_experiment
http://diveintomark.org/archives/2004/01/16/draconianism
http://diveintomark.org/archives/2004/01/19/validator-services
I've never felt the compiler was flagellating me, except when I had to take over someone else's code and discovered that they'd never heard of warnings...
Greg Bowers on April 28, 2007 9:25 AMIt's my opinion that if in the beginning of the web HTML standards were as good as XHTML, and clients were mandated to display high-quality, informative error messages on malformed content, then we'd be in a lot better state today. Graphical browsers would all render HTML the same, execute Javascript as expected, etc. Even "Joe User" would benefit as the tools he'd use to output HTML would output with standards compliance as a requirement.
Conversely, programming for the WWW would actually be a pleasure. Instead of shotgun programming, tweaking this HTML, hacking that CSS, we'd actually get work done at a reasonable pace.
To say that the web needs to be forgiving of errors simply because it's widely adopted neglects that it started off on the wrong foot in the first place.
Nicholaus Shupe on April 28, 2007 9:50 AMit's a deadlock, any 'strict' web browser will never become popular because they are unuseable in the real world. But the popularity of a tolorent browser will only encourage bad coding.
mpan3 on April 28, 2007 11:11 AMmpan3, non-web programmers have to adhere to strict language syntax and catch any possible errors why shouldn't web developers? Personally, I check to make sure my work is strict XHTML, CSS and doesn't produce JS errors. I test it all in multiple browsers. I don't see why web developers should have it easy...
Supergibbs on April 28, 2007 11:34 AMIt's a double edged sword as no two "workarounds" behave the same way. It makes designing an HTML page to look the same on all browsers a real nightmare.
Of course, even if all the browsers were strict, there is still room for interpretation in any spec. But at least the differences would be minimal. At least I would hope.
Haacked on April 28, 2007 11:38 AMThere is a great money-making opportunity here for the web site validation people.
Brendan Dowling on April 28, 2007 11:48 AM
Gosh. It's like millions of people have a vested interest in teh Intarwebs being user friendly, or something.
Dylan Brams on April 28, 2007 12:10 PMUsing variable i in that loop without var keyword makes it to refer to global variable i within the script and not local one to the loops scope. Most likely a programmer error..
Samuel on April 28, 2007 12:12 PMDave's evaluation of what is going on in the Javascript is incorrect. "i" is not initialized to startIndex at the beginning of each iteration of the loop in Firefox:
/* prints 0 to 999 in both IE and Firefox */
var endIndex=1000;
var startIndex=0;
for(i=startIndex; i endIndex; i++) {
document.write(i + 'br');
//Do some stuff here
}
My guess is that your "//Do some stuff here" manipulated (or called functions which manipulated) a variable "i" as well, and in Javascript, if you use a variable without declaring it with "var", the scope is global (otherwise it is local to the containing function). Why this does not affect Internet Explorer is anyone's guess. Without seeing the remainder of the source code, I'd speculate that there is separate code to support IE and Firefox and only the Firefox code uses another global instance of "i".
However, as the sample code above demonstrates (tested in Firefox 2.0.0.3 and IE 7), the loop completes normally. There is no bug, error or differences between the way IE and Firefox handle the scoping rules and loop.
Grant on April 28, 2007 12:19 PMThe comments completely broke my code. Hopefully this works:
/* prints 0 to 999 in both IE and Firefox */
var endIndex=1000;
var startIndex=0;
for(i=startIndex; i endIndex; i++) {
document.write(i + 'br');
//Do some stuff here
}
Brendan: you might want to take a look at the WHAT-WG's "HTML 5" work (which has now been proposed to the W3C's HTML working group as a starting point for new work); one of the major design goals of the specification is to set out unambiguous rules for handling malformed HTML.
Doesn't help with JavaScript (and Grant is almost certainly right in diagnosing global scope as the root of Dave Murdock's loop problems, in which case Firefox is behaving correctly), but at least it's a start.
James Bennett on April 28, 2007 12:51 PMJavascript is the single reason I'm looking to move away from web programming as a career. It is the cause of 90% of my testing and debugging. I want to debug logic, not fiddly cross browser issues.
Tim on April 29, 2007 2:18 AM Javascript is the single reason I'm looking to move away from web
programming as a career. It is the cause of 90% of my testing and
debugging. I want to debug logic, not fiddly cross browser issues.
Use Flex. That gives you flash apps that behave the same everywhere. The language of Flex is ActionScript -- JavaScript with decent static typing. It's really amazing how that "simple" addition fixes JavaScript's stupidities.
rblaa on April 29, 2007 2:46 AMJavaScript errors are so pervasive, in fact, that it's easy to understand why IE demotes them to nearly invisible statusbar elements.
Everyone does, actually, and MSIE is the only browser who switches to modal dialog when you allow it to launch a debugger.
Oh, and it's the only browser whose error messages completely and utterly sucks.
Warnings and errors are good for developers. That kind of environment for JS is *harmful* to the people *writing* JS code.
Bad developers don't care (when they have a strict compiler, they change the code to make the code compile, they don't try to understand *why* they have errors and make their code better), good developers in JS have LINT, and Firefox' Strict mode, and Firebug (of course these are not enough because -- business as usual -- IE still has retarded behaviours, but that makes for a much stricter Javascript environment)
Masklinn on April 29, 2007 2:50 AM"We scratch our heads and wonder why the browser can't give us the punishment we so richly deserve for our terrible, terrible mistakes"
Priceless :))
KristofU on April 29, 2007 2:54 AM"Use Flex. That gives you flash apps that behave the same everywhere."
Bzzzt! That answer is incorrect. Those flash apps fail to work on my Linux/PPC system, as Adobe refuse to release a player for that system.
The whole basis for the success and popularity of most of the web is due to its reliance on open standards that are implemented by multiple vendors for any platform you care to name. Flash cannot work for a fair proportion of computing devices because of this. Take mobile phones. Many of them now run Linux run on non-x86 chips and have full network stacks and are capable of browsing the web, but flash players simply will not work for them.
The majority of the web is client/platform independent. Lets keep it that way, please? Lets not go back to the dark ages where vendors locked you into proprietary file formats. We're only just starting to get out of that trap with document formats and ODF.
Having things behave the same everywhere (given a sufficiently loose definition of "everywhere") because only one vendor is *capable* of supplying the software required to view the content is *not* a step up from HTML/JS.
Adam on April 29, 2007 3:11 AMLogical/runtime errors are handled about the same as any other language.
True, but JavaScript is also a dynamic language, so you don't have the same compile-time warnings as you do in statically-typed languages.. or dynamic languages with static declaration options.
Jeff Atwood on April 29, 2007 3:17 AMHave to agree with Adam on this,
"Unfortunately, the Draconians won: when rendering as strict XHTML, any error in your page results in a page that not only doesn't render, but also presents a nasty error message to users."
That's why it's called STRICT. If there's a problem on my page I'd like to know about it so I can fix it, rather than relying on some browser behaviour to kick the issue under the carpet.
"forgiveness by default is what works"
...but makes us lazy.
"forgiveness by default is absolutely required for the kind of large-scale, worldwide adoption that the web enjoys."
That's a rather magnificent jump to conclusion there, I think. All things considered, should the tools enforce the developers to follow the specification, the eco-system of web development might actually be in a much healthier state today.
Take a look at web browsers for instance. If the implementations would stick to the specification and avoid making their own interpretation then barrier to entry for creating new HTML/CSS/Javascript capable clients would be much, much lower. We'd see an environment where the technology would be driven by innovation rather than be hamstrung by the quirks of other dominant implementations.
Of course, this situation serves certain vendors just fine. Those vendors are much more interested in customer lock-in rather than truly pushing technology forward and enabling us to do MORE with the existing foundation. A certain vendor missed the Internet boom so completely they've done nothing since other than try to keep things from moving forward at an ever-increasing pace.
Same from developer perspective -- imagine being able to actually produce functionality for the web instead of wasting most of your time debugging "forgiving" (read: wrong) implementations of various clients out there. Imagine that wasted effort actually spent on innovation, or being able to code that neat UI feature rather than finding a certain client implementation doesn't support the spec correctly, and giving up.
You're arguing that the web would not have come as far as it had if the shitty "forgiving" browsers didn't exist. I'm wondering how many years we've fallen behind from where we could have been had the early implementations come with at least a modicum of quality, and with an expectation that the developers are able to produce code that actually meets the specifications. Had the mass-market tools for producing web content actually created documents that validate correctly against the specs, how much more could we have achieved by today?
To me the answer seems clear. Forgiveness in this case has led to a situation where the developers are stuck waist-deep in a mud of "forgiveness" instead of being able to create something greater and better.
Dis Gruntled Um, the web is pretty much, by definition, platform- and user-agent-independent.
If you want to say "this practice is breaking *IE*" then say so. Don't claim it's breaking "the web", as it's not. It's breaking a single browser.
Yes, IE has a lot of market share. But IE is not "the web". If you want to complain about /de jure/ standard javascript breaking IE, complain about it breaking IE.
Given that the number of different platforms that IE is not even available for is increasing as time passes (OS X, mobile phones, linux desktops, etc...), and they're getting more popular, writing for IE-only is becoming less and less prudent.
Adam on April 29, 2007 5:35 AMPersonally I think Opera handles the XML errors the best... it will render as much of the page as possible (up to the error) and show a huge message explaining why it cannot go any further.
However, when it comes to the 'real world', I develop my websites using FireFox (because of all the developer tools) and have the pages being delivered with the XML header... that way, I cannot even see the page until I get my errors fixed... then on the Live site, the configuration file (which detects which server it is on) will drop the pages into the more forgiving HTML rendering.
Craig Francis on April 29, 2007 5:45 AMSaying that XHTML strict should go ahead and display is like saying your compiler should have known what you meant and tried to run the code anyways. But by the standard of the XHTML strict spec, the document is not conforming.
What I find broken about the example given is: "Unfortunately, the Draconians won: when rendering as strict XHTML, any error in your page results in a page that not only doesn't render, but also presents a nasty error message to users."
I have never seen the w3.org validator validate a page that wasn't able to be validated by any browser. Perhaps the validator he was relying on is the one that's broken?
Jonathan Johnson on April 29, 2007 5:59 AMAdam Bosworth calls this sloppy:
http://www.adambosworth.net/archives/000031.html
Tim wrote:
"Javascript is the single reason I'm looking to move away from web programming as a career. It is the cause of 90% of my testing and debugging. I want to debug logic, not fiddly cross browser issues."
You're are confusing two different issues; namely Javascript development and multi-vendor platforms. Developing solely for a single platform (ie Firefox) using Javascript is totally pain-free. Extending that support to Opera, Safari and especially IE is where the pain appears.
None of this pain is due to Javascript.
So, if, say, I decided to abandon web development and build everything in Javascript/Silverlight, the only reason it would be less stressful would be due to the single-vendor platform.
RichB on April 29, 2007 6:29 AMI started a comment here, and when I got to three paragraphs, turned it into a blog post: http://www.nedbatchelder.com/blog/200704.html#e20070429T080859
Ned Batchelder on April 29, 2007 7:04 AMOnce standards cease to be hijacked, extended, and bastardized by manufacturers, we might get something workable and ubiquitous.
Also, I shudder at exhortations to use add-on junk like Flash. Code for the Web! Don't use proprietary add-ons! One man's ActiveX is another man's blank page!
philhege on April 29, 2007 7:15 AM@Grant: The problem, is, naturally, that your code is not quite correct for the test, since 'i + "br"' runs the risk of converting i implicitly to a string, which plays holy heck with the loop. Written using 'i.toString()' in place of i is the correct way to do it.
I ran both cases in IE7 and FF2.0, and I didn't see a problem.
And those of you that agree with Dave Murdock unfortunately disagree with ECMA; ECMA-262 12.6.3, explicitly permits for() without var in the first expression list. Were IE and FF to get sticky over that point, they'd not be compliant with the specification. In a world where everyone insists on "compliance" with this or that RFC or specification--resistance is futile--then you have to start asking yourself about how good the RFC or specification is.
As for all those error boxes popping up on web pages*, what I've seen is that most of the errors have to do with annoying pop-up ads that are trying to violate sandbox constraints. The "developers" of those snippets really ought to learn about "try()/catch()" and playing nice with end-users. Of course, since they're writing pop-up ads, they probably have no interest at all in playing nice. Either that, or it's years-old scripting that hasn't been updated in recognition of the security holes being closed over the last couple of years.
* I see them, too, as about half my development time for the last decade has been spent writing Javascript, and I keep the debugging on AT ALL TIMES (everyone developing scripted pages should). CNN's website is particularly bad for this.
Brook Monroe on April 29, 2007 7:35 AMHi man,
I like reading your blog. One problem however, I am stuck on IE 5.13 (Mac OS9) - no dosh for upgrade to X - and I have to call up the source in order to be able to read anything inside "pre" tags on your page. While I read through the source I found that you don't close your paragraphs. Close them - like you should do with block-objects - stick the pres in between as block-objects in their own right and everybody will be able to read everything on your page. I tested it. Yeah, some browsers are sticklers.
Carry on the good work!
Grant is right, the JS "example" simply isn't true.
Run this in Firefox Error Console:
startIndex = 10; endIndex = 20; rv = Array(); for (i = startIndex; i endIndex; i++) { rv.push(i) }; rv.toString()
And guess what you get?
rv = [10,11,12,13,14,15,16,17,18,19]
Didn't you recently complain about Bloggers not being Journalists? :p
Sloppy HTML has it advantages and strict XHTML has as well.
XHTML is XML, so it is more "portable" between different Applications.
You may work with XSLT on it; you may embed other XML languages (such as SVG/MathML) into it; you may use any XML parser to read it; those parsers/writers supporting DOM may also manipulate it easily.
And not being able to be lazy is not a bad thing. Developers need to write better markup, which usually leads to more compatible code as the browser simply doesn't have to "guess" that much.
Most bigger sites use a CMS anyway, so that "strict" shouldn't be a problem.
See Feeds (RSS/Atom) for example. They are XML documents too. Need to be strict.
And yet, even although almost every major site has a fancy RSS icon somewhere nowadays, I rarely see a broken (XML parser error) feed.
Compare this with the relative numbers of "broken" sites due to IE only fixation. Laziness sucks.
So, in my opinion, HTML is a good tool for starters, HTML Strict (yep, there is) is for those wanting sites that work, and XHTML is the logical step to interoperablity.
While sloppy JS is a tool for nobody, and strict JavaScript (addressing the browser quirks as well) the only solution. You don't write sloppy Whatever(tm) code after all, do you?
PS: Nice tool for debugging JS in Firefox/Mozilla is to about:config both, javascript.options.showInConsole and javascript.options.strict, to "true".
Nils on April 29, 2007 8:23 AMBrook Monroe:
@Grant: The problem, is, naturally, that your code is not quite correct for the test, since 'i + ""' runs the risk of converting i implicitly to a string, which plays holy heck with the loop. Written using 'i.toString()' in place of i is the correct way to do it.
What implementation does act like this? This would be a WTF.
You're not assigning i. You pass the intermediate/temporary result, which is indeed a string, as a function parameter.
"While I read through the source I found that you don't close your paragraphs." - bernhard
The p doesn't need to be explicitly closed, even in HTML 4.01 Strict. According to the http://validator.w3.org/check?uri=http%3A%2F%2Fwww.codinghorror.com%2Fblog%2Farchives%2F000848.html, none of the errors seems to be show-stopping. It might be CSS issues, but I don't have IE 5.x to test with.
"The thing I miss from XHTML is auto-closed tags, mainly just because looks a lot cleaner." - Foxyshadis
Are you sure that it's XHTML? The following is HTML 4.01 Strict according to "http://validator.w3.org/": '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" titleHTML 4.01 Strict/titlepThis is an example of a strict HTML 4.01 page. The html, head and body are optional and p doesn't need to be explicitly closed.'
Oh wait, you probably meant that you "miss from HTML".
everling on April 29, 2007 9:06 AMJeff, in reference to http://www.codinghorror.com/blog/archives/000846.html, perhaps you should allow visitors to use basic HTML or BBCode so that our comments would be a lot more readable. It's very hard to read several pages of plain comments.
The ability to quote, link and emphasise would be nice.
everling on April 29, 2007 9:12 AMYou can't compare the two. Apples and Oranges.
If you write malformed HTML,the browser attempts to make the best sense of possible and render something.
If you write javascript with syntax errors, the interpreter tells you, somewhere, and the doesn't run any more scripts on the page. Logical/runtime errors are handled about the same as any other language.
Scott on April 29, 2007 9:56 AMReal XHTML didn't fail because it's draconian, it failed because Internet Explorer doesn't support it. It never had a chance.
Brendan Taylor on April 29, 2007 10:51 AMAbsolutely agreed. Fortunately, we'll most probably have HTML5 (aka Web Applications 1.0) instead of XHTML2.
http://xhtml.com/en/future/x-html-5-versus-xhtml-2/
BTW IBM's PL/I compiler was quite forgiving (Because those days you had often just one compilation of you card deck per day. Can you imagine that now?) and tried to do lots of work to fix programmer's errors and to have as much combilible code as possible. And many times it was right and helped a lot. E.g. it added semicolons if they were missed, and nowadays Javascript does the same. Most of the time - correctly.
YRU2L8 on April 29, 2007 11:18 AMeven in the microsoft web sites (msdn, etc) there are a bunch of javascript errors in IE7
Eber Irigoyen on April 29, 2007 12:24 PMFrankly I feel that developing against FireFox is the source of many of the script errors. I'm just as sick of the CSS hell it fosters and this practice is breaking the web.
Whatever you think about IE... too bad, it's the de facto standard. Get over it, or get fired. Is there a place to report FireFox ninnies for employer action? There surely ought to be.
Dis Gruntled on April 29, 2007 12:37 PMYou'll never have a problem with XHTML if you use dom-to-xml writers, but you _always_ will eventually if you don't, no matter how careful you think you are. I don't see any point to using it over HTML in any other case anyway, except as a more-dangerous alternative. You're not parsing the files as an attempted semantic web, you're not sparking a well-formed revolution, you're just getting them to display in browsers, and as long as you use good HTML practices they'll work cross-browser and cross-platform better than forcing XHTML will. (And since a large amount of HTML is generated by people who will never be programmers, applying programmers' rules will doom it, like XHTML.)
The thing I miss from XHTML is auto-closed tags, mainly just because textarea/ looks a lot cleaner. .
Javascript needs to break more because it's more than just a glorified markup language, and it does, even if it looks so permissive. But it doesn't have memory lifetime issues or a need for top performance; similarly forgiving languages like ASP and PHP have certainly become so popular because they bend over backwards to do the right thing, and finding the right balance is important for the success of a language.
Foxyshadis on April 29, 2007 1:01 PMIronically, Web Developer toolbar on FF 2.0.0.3 is throwing JS errors on the main page of this site...
psycotic_furby on April 29, 2007 1:10 PMthe obvious problem here is that we must make sure every interpreter reacts the same when it encounters incorrect code. this is close to impossible. but it will result in the users screaming: "$MY_BROWSER shows it right, yours must be broken!" when actually it's the code that's broken. in the real world, $MY_BROWSER will be IE. we all have to live with that.
Felix on April 29, 2007 1:45 PM"The permissive, flexible tolerance designed into HTML and JavaScript is alien to programmers who grew up being regularly flagellated by their compiler for the tiniest of mistakes. Some of us were punished so much so that we actually started to like it."
Riiiight. And when programming in C or C++ do you -
a) Turn all warnings off and ask the compiler to be as lenient as possible.
b) Turn all possible warnings on and make the compiler as strict as possible.
Having the compiler warn you about all your possible mistakes allows you to *fix* them. A warning on that infinite loop would have allowed the developer to have fixed it before a client ever had it lock their browser. Having a compiler/parser barf on a bad colour would allow the developer to fix the problem before a user ever saw "sea green" as blue (or even green), ruining your company's precious branding.
The problem with code containing errors is that it fails differently on different compilers/interpreters. If you never know about the error, you're never going to realise that the fact that it's failing in a way that looks OK on your system is a fluke, and that it might do anything on anyone elses.
Warnings and errors are good for developers. That kind of environment for JS is *harmful* to the people *writing* JS code. And the thing that's harmful (well, annoying at least) to *users* of JS, is bad JS written by developers who don't have a JS environment that tells them when their code is bad.
Adam on April 29, 2007 1:57 PMThe problem is that the specification defines what to do when the HTML is *valid*.
If you want browsers to gracefully degrade and handle crap malformed HTML then they'll do it inconsistently and you've opened another cross-browser compatibility issue.
One alternative would be to define how to handle rubbish in the spec. This means a bigger spec which adds complexity to the parsers and renderers...
Too many people publish HTML littered with errors they either don't realise or don't care about because it "works".
Later on they find out it doesn't.
You wouldn't want your C# compiler to let you ship binaries with a best-guess for each error (that also varies per runtime implementation) so why on earth would you advocate it for HTML?
[)amien
Damien Guard on April 30, 2007 2:12 AMjavascript: in the URL also gets you the console since Netscape2.
People need to give javascript a break. It is essentially the glue of the internet for 10+ years and has spawned way beyond its initial design (the sign of a good design or language that is useful). Many javascript errors are from ads or adblockers, or just bad non cross browser script. Its the most visible glue of the web and thus you see more problems with it. But if javascript is a problem for you I am not sure that you should be developing at all for the complainers about javascript.
ryan on April 30, 2007 4:12 AMIt'd be nice if badly written pages were penalized by browsers in a way that would get users on their back without breaking sites. e.g., render quirks mode s l o w l y (unfortunately users would blame the browsers that did this). A better plan might be a standard to log the error back on the website - eg have browsers do a HEAD request for '/quirks?etc...(spam filter stops what I typed)' if they drop into quirks mode. It's no worse than favicon.ico requests, but might keep the designers honest.
Baz on April 30, 2007 4:51 AMIt might be nice the browser displays something even when there is an error. The problem is, tons of those pages with javascript errors DON'T ACTUALLY FUNCTION. Since the person responsible for creating them never noticed the error instead the user of the page is just S.O.L. I don't know what the correct solution is/was but I hate going to a page with a javascript error, trying to submit a form or click a button with javascript attached and getting nothing because of the error. I don't see how that is a win.
greggman on April 30, 2007 5:19 AMSurely in part the staggering success of the internet has been because anyone can create some html and a bit of javascript and get it to work.
Web pages are small, javascript programs are small, there are very few interdependencies, the need for structure and discipline to make a large application hold together without collapsing into chaos just isn't there.
How can we forget *THE* golden rule, "Keep It Simple Stupid", and apply it to the whole development process and not just the end result.
I remember when every computer came with a tolerant usable programming language as standard, and it was expected a lot of people would have a go, even if it was just scrolling their name round the screen. How many of these for fun programmers started careers this way. Truly, I lament the fact that windows has never had a usable programming language as standard, especially one as tolerant as a typical web page.
Vive la difference that what I say.
David Hutchinson on April 30, 2007 5:30 AM"[Where VBScript is concerned,] the end user of a web page script is someone who has absolutely no ability to understand the error. If they do understand the error, they have no ability to go to the web server and fix it. Therefore, never produce error messages unless you absolutely have to."
-- Eric Lippert
http://blogs.msdn.com/ericlippert/archive/2003/10/06/53150.aspx
The vast majority of end-users judge their web browsers like this. Pretty much nothing is going to change this. The behaviour kind of goes like this: "I want to see Website X. When I use firefox, I can't see it. When I use IE, it works. IE must be better than Firefox, because it allows me to accomplish my goals." The same behaviour is in action when people turn off all the options that protect their web browser from attack. Only two or three responders seem to have absorbed this basic lesson of human behaviour.
At a guess, as we increase the amount of automatically generated DECENT, VALID client-side script/markup, so will we see in APPLIED web standards. STRUTS was a good move, .NET moves in the right direction too. A deployed end-user environment like Flash will work too, since when users install the plugin, things will start working, thus fulfilling their goals. The fact that none of these are quite as good as we'd like doesn't mean that they won't be in the future, or that someone who does fulfill these things won't move in.
Chris Moorhouse on April 30, 2007 5:39 AMI think SAS might be more forgiving than HTML/JavaScript. The SAS manuals actually give a long list of spelling errors that will pass as the original word.
For example for "if" you could spell it "i f" or "iif" or "iff" or "fi" and it will still go through as "if". The language is the most forgiving I have ever seen.
Billkamm on April 30, 2007 6:58 AMI think developers get off lightly in respect to Javascript errors. I've worked with a lot of developers that don't take Javascript coding seriously and who often code it with the attitude of "thats good enough". Many developers do not write client side code with the same care as they would server side code when the consequences of mistakes can often be equally grim. If you wouldn't gamble with unhandled exceptions in server side code why would you in client side code?
I believe Javascript skills are more of a requirement for web developers than an option. Server side programming alone cannot provide the useability that web users demand these days and I think many developers miss that. I write a good deal of client side code and I take it just as serious as the server code.
Brian K on April 30, 2007 7:02 AMI completely agree with your basic premise of 'forgiveness by default' being better for the web. I prefer the term 'degrade gracefully', and classify it as one of three styles of error handling - the other two being fail fast (what you call the 'Draconians') and ignoring errors.
I've written about the relationship between error handling and reliability (see http://www.basilv.com/psd/blog/2007/error-handling-and-reliability ), but I have not really thought about it in the context of usability and user adoption, so I really liked how you presented that viewpoint.
Basil Vandegriend on April 30, 2007 8:08 AM
Question: How did the developer upload a broken site if the clients are only displaying errors? Shouldn't he develop against browsers his audience is using, and have seen the error message?
This lead to thinking: The developer should be using the strict browser as his primary testing platform, so that he'd be catching those errors.
Which THEN led to thinking: Why doesn't someone make a developer oriented browser, which strictly catches things like javascript and html/css errors so that we can produce working code and not care about what kind of client they are using.
Anyone less lazy than me want to take up that project?
Telos on April 30, 2007 9:29 AMI just noticed, while visiting a badly-designed site, that the Script Debugger will also fail on other malformations (e.g., "Img" as a tag in a claimed-to-be XHTML page). Some times the bugs are so bad that I can't even get my cursor off the page or the failures are in a loop that won't quit and I have to use the Task Manager to quit the browser.
This is the whole problem about whether or not HTML was intended to be written by humans and sites that humans hand-coded in Notepad or not had to be accepted.
I do know that I am wasting my time reporting buggy sites and meanwhile I have a sucky experience. The answer for me is to turn off the script debugger except when visiting pages of my own.
The irony, of course, as already noted, is that the standard IE-sucks litany will be echoed by those producing sites that are unbearably defective and being righteous about how we should start strict-checking against the zillions of pages that are out there.
It is also interesting that many RSS feeds and blog sites don't validate the embedded from comments and entries, claiming it is XHTML when it isn't. So even RSS readers have to be forgiving because those DTDs are often bogus and the entries are a mess. These items are all produced by software and it is not something under the blog author's control or above the level of awareness.
OK, going to turn off the debugger now.
orcmid on April 30, 2007 9:43 AMIf browsers suddenly started punishing web devs the way they ought to, chaos on the web would reign. It would be a rough time for everyone. The upside to this doomsday scenario is that we would all be forced to fix our broken code and learn the RIGHT way. Like I said though, chaos for months, especially that first week - ouch.
oftencloudy on April 30, 2007 9:53 AMOnly chaos for the developers though, the users would just see a lack of updates for a couple weeks. ;)
Telos on April 30, 2007 10:02 AMI discovered this as well, coders need to realize that you have to check for certain variables and things to ensure the user is seeing what you think they're seeing.
live tv on April 30, 2007 11:17 AMThose who are unwilling to forgive others cannot truely forgive themselves...
rabid wolverine on April 30, 2007 11:29 AMMaybe I'm a jerk, but I use IE, and make my website to run on IE. I need to branch out to at least Firefox. Thing is, though; I thought it was standard that one would test a page before quitting for the day. I can't imagine just blindly tapping out code and then shutting down without seeing the finished product and playing with all of the features. I currently have one non-working page, and I warn people before they go that it does not work yet. I think I'm going to make my own Under Construction page to put on things to come.
Mickey on April 30, 2007 11:51 AMFor such a fluid world as the internet, you cannot have strict coding. When I got into web development I had a guy tell me that I should code everything in the latest and greatest standards, XTML and CSS. Sure enough, I came back to him a week later with a page that made him bow before my prowess, it was perfectly coded in XHTML 1.0 Strict and external CSS. Today I build pages that LOOK 30 times better than that page, but probably don't even come close to XHTML compliant. The point? It really doesn't matter if W3C says your page is valid. The user doesn't care, as long as the page is attractive and intuitive. Also, the browsers themselves don't even conform to W3C standards, so the desired effect of a standards-based system, cross-compatibility, is totally lost, and I don't think a few draconian programmers sitting at home hammering out perfect XHTML pages is going to convince Microsoft to start playing standards ball.
Mattkins on April 30, 2007 12:03 PMMattkins:
If developers would stop making code adapt to every browser, browsers would have to start following standards. Hacking everything to be IE compliant is exactly what lets MS get away with such a poorly compliant browser.
Granted, a few developers making their code compliant won't matter. Most developers have to do so for there to be an effect... which is probably not feasible.
Telos on April 30, 2007 12:44 PMIf everyone would quit being so cute with their presentation layer, the information would have a chance to get to the user.
John A. Davis on April 30, 2007 1:20 PMI disagree with your premise of 'forgiveness by default' being better for the web.
The road to hell is paved with good intentions, and the only way to get the genie back into the bottle is to tighten things up.
Sorry, but if something is broken, it should not be out on the web. Hand holding through half-crashes is dangerous as hell. What about the security implications of this? It seems like the browser should just shut down the session, as the site isn't even ready for prime time. Sorry if this sounds extreme, but it's really the way it should work. A unhandled error or exception should bring things to a screeching halt. The browser should not play along. End-users could then judge the quality of the sites they are visiting (It is either working, or not), and we would all be held to a higher standard.
This lack of "clarity" on the web is one of the reasons I left web programming ... hoping in the mean time that XHMTL and stronger standards would become mandated at some time. I guess I'll continue to wait, which is sad. I see the dilemma, but the solution to me is extra, mega, super-duper crystal clear.
rebound on April 30, 2007 1:46 PMI don't know if this has been said before, but even though IE allows
for (i=0;ix;i++)
if within the loop, you call another function that also has an "i" variable, that "i" variable will retain the value of the calling function, as if it were still in scope, unless it too is preceded by "var"
I learned this at 3 AM one night... crazy script!
CptBongue on May 1, 2007 2:28 AMTelos:
I see your point exactly, which is the reason I at least put some effort into good coding standards, I just don't worry about it as much as I used to. I'm a pragmatist, which means I realize that for every small coding masterpiece we pump out, there are fly-by-night coders slamming the biggest pieces of trash they can and somehow making them popular *cough*MYSPACE*cough*. As long as these festering boils on the face of the internet remain so popular, tightening standards by conforming to them while we code our smaller sites isn't going to be enough to prove to Microsoft that they're going to lose IE users due to poor browser compatibility.
Mattkins on May 1, 2007 12:49 PMAs I read a lot of these comments, I see a startling trend. I've seen several posters who think it's a better idea to GENERATE code using a program than hand-type it yourself. You have got to be kidding me. I don't trust any development environment enough to write my code for me. My code needs to do exactly what I tell it to do, nothing more, nothing less, and if you let Dreamweaver or Visual Studio write the code for you, then how do you know exactly what the code is doing? Generated code is exactly what got us into this mess of bad web-pages in the first place. If there weren't applications out there that gave us easy-to-use WYSIWYG editors for building web-pages and applications, the only applications out there would be written by someone smart enough to code manually, and therefore know exactly what the code is and what it's doing.
Mattkins on May 1, 2007 1:07 PMI answered all of the comments that people had posted on my blog about the JavaScript problems I was debugging:
http://www.innerexception.com/2007/04/tip-make-sure-you-declare-javascript.html
Putting var in the for loop does solve the problem because it scopes i to the function. Another function was being calling inside the for loop with //Do some stuff. This function also had a for loop which, you guessed it, just used i without declaring it with var, thus the collision and the Firefox hang. Firefox did not detect the deadlock. IE appeared to complete the loop without error. I drew the wrong conclusion about the scope of i after putting var in front of it because in my years of writing JavaScript using var in the for, I assumed it was scoped like any other C-derived language, the variable exists only in the loop. Because I had never run into a problem like this before, it never occurred to that for(var i..) was scoped at the function level, and I had never declared for(i... before, this was a bug another developer had unintentionally introduced, so I thought it was an abbreviation of for(var i...) that Firefox was having a problem with.
Dave Murdock on May 1, 2007 1:13 PMTried and tested formula, Code in IE, run i nfirefox.
BTW: wats with the captcha?
i have seen a lot of comments so far saying xhtml is just a joke and only hard core developers are using it in their basement. what most of you tend to forget is that not everyone that uses the web can see as well as you (or at all) or can use a mouse or a keyboard. that being said, xhtml conformance will allow the tools that help these folks browse the web do their job more easily, as such these users will have a much better time enjoying your site.
an example: someone is blind and is listening to a computer generated voice read your website to them. did you know that these screen reader tools read your source from top to bottom? that means if you have your navigation as the first thing in your source, they must listen to it on every page they visit before they hear any content on the page.
a solution?: so let's say you want to put your navigation at the bottom of your source in light of this new information. this is easy enough, but wouldn't it still make logical sense to have the navigation at the top for those who are not blind? of course it would. so you work with css and relative or absolute positioning to get the navigation at the top of the page. herein lies the problem. different browsers behave differently when you try to position elements on your page.
if browsers were all standards compliant, that means they would all behave the same way, there would be no second guessing, and your absolutely positioned menu navigation would be in the same place no matter who was looking at it in what browser.
but browsers are not standards compliant, and clients paying for web development services rarely care about whether or not the site you are developing is standards compliant. they don't want you to spend twice as long developing just to make your pages validate.
cowgod on May 2, 2007 9:49 AMAnd you know what ? This page doesn't validate...
The only thing that can save validation of content is to make it a good thing for coders.
This can be done by making Firefox, Safari, Camino, etc., a significant market share of the web.
How will make a website that will show well in all these browsers ?
You can test them... or validate once.
I'm a Firefox ninny, and yet I'll agree that IE is the defacto standard.
Lots of people use IE. Most people on the web surf in IE.
But no one that *I* personally know uses it. Everytime I've designed a page to work in IE only, I've had my friends come back and say "nope, doesn't work in Firefox, so I can't use it".
Heck, even my mother uses Firefox and she's the least technical person I know. She likes it because spyware chooses to infect IE with its toolbars over Firefox, and she's the type of person to click 'yes' on anything without thinking.
My university uses Firefox by default too (and we have open office too).
I care about these annonymous IE users, but I care more about people I can see and touch, and people who can complain to me in person.
I think I may have figured out the "sea green" problem. Maybe firefox only looks at the first word, and Opera was the only one that looked at the whole value? "sea" sounds like it should be blue to me. ;)
Sean on June 27, 2007 12:28 PMerr, yeah, and nothing can do Acid3.
But seriously, I suspect that those javascript errors are down to IE. I keep my Safari error console up quite often, and really, a decent site does just work.
da bishop on September 24, 2008 1:03 PMThis is an interesting article, but I don't get what the gripe is. For a developer, there are tools to check one's code for errors and fix them (like Firebug for Firefox); for the end-user, it's probably good that browsers don't interrupt an experience to notify them of the developer's mistakes. It's not like the browser can fix the problem, so just proceeding anyway seems like obviously the correct behavior. If developers need more robust error-checking or prevention, what is needed are more robust tools for writing and testing, not alteration of the end-user platform. IMHO.
Jason Boyd on February 6, 2010 10:02 PMI don't know, I really wish javascript would catch things like this:
var counter = 5;
x = arr[cuonter];
Really aggravating if you ask me.
John Riston on February 6, 2010 10:02 PMHTML is markup and Javascript is code. There is a difference. One is inspected (parsed) and the other compiled. So I can see a some leeway with the Browsers on HTML. But if there is a compilation errors, should compiler deal with that? Probably not. Its easy to deal with markup issues, because the renderer will implement some sort of default behavior or just ignore it all together.
Hiding javascript errors encoruages bad programming practices, maybe its not the programmers fault, because each browser has its own Javascript compiler and it may be difficult to support all browers 100%.
Let's not forgot that original web was meant for content not as a scripting language. Netscape introduced Javascript and then Pandora was out of the box for good. Microsoft followed suit and supported scripting as well but its implementation was not the same. Marketshare eventually dictated everything work on IE and if you had time, test other browsers. Sometimes scripts that would work on one version of IE would break on the next version of IE. I think Microsoft gave up strict compliance because things changed so rapidly so they let errors occur. Getting Javascript to work across all browsers is nearly an impossible task because each one has its own interpreter. Now if the shared the the interpreter/compilier, things would be a lot easier.
For our system, we have a lot of data files in XML format and we validate them all versus our schema files (XSD), if they don't pass, they don't get read or imported and the user gets an error. We have no leeway on that. So in that respect we are Draconian, but in a good way. Garbarge in, garbarge out. Don't trust your users (partners), etc.
For HTML, XHTML, XML, there are tools and schema validators that make sure the markup conforms to W3C standard specification.
For Javscript, I am not sure if there is anything to validate your code.
I found this, but do not know how good it is:
http://www.dhitechnologies.com/
The comments to this entry are closed.
|
|
Traffic Stats |