Think Before You Hack

I’ve just been looking at a ‘broken’ site in IE7 and helping a friend diagnose what the problems are. I think people tend to assume that if a site renders happily in a bunch of different browsers, but has problems in IE7, then the browser is bad. The default response is then to add some hacks to make IE7 work correctly.

This is a bad way to go. Each problem that I’ve looked at so far, IE7 is actually rendering correctly based on the instructions it understands. We just fixed a big layout problem where the root cause was a container div not stretching to contain it’s floated children. However this was the correct behaviour. Based on the instructions that IE7 had parsed and understood, it was rendering correctly.

The fact that those instructions didn’t arrive at the desired layout was the problem, not the browser rendering. By taking the time to diagnose the problem and understand why it was rendering in a certain way, you can solve the root issue rather than adding a new layer of hacks on top of broken instructions.

Generally IE7 will behave in a very logical way – it’s really worth taking the time to figure out why something looks wrong, rather than jumping straight in and hacking.

UPDATE: the particular issue we were looking at was how to get an element to contain it’s floated children. This has been discussed already on 456 Berea Street and Malarky.

Posted:

October 3, 2006 @ 10:02

Categories:

Development

Tags:

, , ,

Comments:

2 comments so far

Comments RSS feed for comments on this post.

  1. When working with someone else’s software, it’s interesting how it’s all too easy to assume that you are always in the right and anything that’s not perfect is a bug.

    This isn’t just a problem in IE – I’ve seen some horrendous hacks in code that I’ve reviewed and more often than not it’s a lack of understanding of the given framework (.NET, Java, whatever) that’s caused the reliance on “hacking until it works”.

    I do think that the negative press that IE has got up until now has just exacerbated this problem, no matter now unwarranted it is.

    Comment by Mike, October 3, 2006 @ 12:58 pm

  2. I’m actually really happy that all of the strange layout issues I’ve seen so far in IE7 are not bugs – the rendering behaviour seems like a massive improvement on 6. I wrote about this as I caught myself assuming that a broken layout was due to a browser bug – I think the first rule of diagnosis is to be objective and not make assumptions!

    Hacking is always the easy route, but leaves you with a fragile codebase that is hard to maintain. I also think taking the proper time to understand a technology is also much more rewarding on a personal level.

    Comment by Oli, October 3, 2006 @ 1:45 pm

Leave a comment