JavaScript and HTML: Forgiveness by Default

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

For 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:

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.

If everyone would quit being so cute with their presentation layer, the information would have a chance to get to the user.

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

I 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!

Telos:

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

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

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

Tried and tested formula, Code in IE, run i nfirefox.

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.

And 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. :wink:

err, 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.

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

I don’t know, I really wish javascript would catch things like this:

var counter = 5;

x = arr[cuonter];

Really aggravating if you ask me.

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

http://validator.w3.org/

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/