Thursday, July 15, 2010

Ten Thousand Lines of Bad Code

It's been a while since I've rolled up my sleeves and worked on the code behind the screen, and having pitched in to help out with those tasks in the past few days, I'm appalled by what I found there: a tangled mess of code that, while functional, is thoroughly rotten.

My shock and revulsion arises, in large part, from being one of the old dogs, who started back in the day when the average modem speed was 14.4 Kb speed, which seemed lightning fast compared to a 9600 baud model of the year before. And 14.4 Kb was a theoretical maximum - the average functional speed was about 1 KB per second.

In those days, your code had to be tight: every wasted character, every flabby graphic, seriously degraded the user experience where the main complaint was how long it took a page to download. It was difficult, and many developers and (especially) designers hated the constraints.

Nowadays, it's possible to cram a lot more data down the pipe, and unless you go hog wild, the download speed is fast enough that the user doesn't get a sense of delay while waiting for the page they requested to show up in the browser before them. And that's largely a good thing.

The only drawback is that designers and developers no longer need to pay much attention to page weight. Unless they do something egregious, it won't make a functional difference. And as a result, things have gotten very sloppy out there.

A few years ago, I was asked looked at the home page of a site that required a download of 180 KB of data to render. Evidently, some statistical software alerted the owner to the "problem" and they were curious as to the reason.

When I looked under the hood, I found the reasons:
  • The content of the page that was being served was small, probably under 5K. Perhaps half of that was wasted on code that had been commented out in the development process but no-one bothered to delete it, excessive space and tab characters, and other sloppy code practices. But this was minor.
  • The majority of the waste was images - and that's not saying that the images were unnecessary, just that they had not been optimized for the Web, and were between 70% and 90% flab. Back in the day, developers would skip this task because it could take a couple hours per image through a trial and error process. Now, there's a "save for Web" option in PhotoShop that takes a couple of minutes to try various formats and compression rates, so there really is no excuse.
  • Another huge chunk was external CSS that, in addition to being full of complete junk (commented-out codes and whitespace characters), included loads of styles that were not used on the page itself. Perhaps hey were used on other pages, or just vestigial, but they weren't needed on the home page.
  • Another sizable chunk were external JavaScript files, of the same nature: commented-out code, a blizzard of whitespace, and unnecessary functions
If memory serves me correctly, I was able to reduce the page size by about 70% in about four hours effort, which didn't address every little thing, just the major issues. The reaction: complete indifference. I don't believe anything was done to address the issue after that - and looking at the same Web page today, it has swelled to 345 KB, so their curiosity about the site's bloat was just a passing fancy, as they have allowed the problem to become even worse.

And again, "problem" is a matter of perspective. Someone like myself, with old-fashioned sensibilities about code, sees it as a serious issue: if 70% (or more) of bandwidth is wasted, the congestion on the Internet could be significantly reduced by simply tidying up. But that's in the nature of environmental concern, something that people pay lip-service to, but still throw trash out the window of a moving car because it's inconvenient to dispose of properly.

It's also a problem for the developers who work to maintain a site, who have to comb through thousands of lines of code and sort out all the references to find out what's "breaking" the page in a given browser. But that's been accepted as part of the job, and I don't expect a low-rank code peon to get much of an audience from the decision-makers.

And as a result, I have largely accepted that pointing out this issue is akin to talking to a brick wall: nobody is listening, nobody cares, and it's probably just waste of breath - or, ironically enough, waste of type.

Which is ironic, in that I'm hammering out a few thousand characters to grouse about the waste of several thousand other characters - but for anyone who's viewing this page, the content is probably only about 2% of the wasted data, given that I'm using blogging software that I expect will add 100 KB or more of completely useless junk on top of the content.

:: sigh ::

No comments:

Post a Comment