Monday, February 23, 2009

Starting From Scratch? Never Say Never

While following my blog quest, I ran across an interesting article which told several compelling reasons why the PHP group is not just re-writing the PHP code from scratch for the upcoming PHP 6.

As I was sifting (or slogging, perhaps) through the comments, I found a link to an interesting article entitled, Things You Should Never Do, Part I by Joel. My curiosity sufficiently piqued, I started reading.

At the risk of over-simplfying, the author basically says, "Never rewrite your code from scratch." It's a bold statement. I can certainly appreciate the intention behind it. From my own experience, I know that rewriting code from scratch can be a long and daunting process.

Most programmers I know (with myself as a definite inclusion), tend to look back at their "old" code and think, "I could do that better if I rewrote it today." Sometimes the code really isn't very old at all.. only a few months. For the most part, I think that having that feeling is a good thing. It means that you've been learning. It means that you have the drive to improve yourself and your work. But acting on that feeling often leads to trouble, just as Joel says. I like how he points out that new code isn't necessarily better than old code -- old code does not rust.

I also concur with his assessment that so-called "old" code is better tested. It is more mature. And I see where I sometimes need to repent of saying that the legacy code is a mess. Joel hits the nail on the head when he identifies that old code looks messy because it is easier to write code than to read it.

So I agree with the spirit of the article. But I take umbrage with a particular word: never.

You (or a software company) should never rewrite their code from scratch? That I don't believe. Now I realize that Joel's article was written back in 2000. I haven't followed his blog to find out if there was a Part II, or if he recanted what he said. But I believe there are some instances where it can be a very good thing to rewrite your software from scratch.

After pondering for a while, I came up with the following list of times when rewriting your code may be beneficial:
  • When you are building something new. Not just a new version, mind you. A new product or perhaps a paradigm shift on an old product.
  • When you are adding new features which the old code cannot support without difficulty. Sometimes you can be painted into a corner by legacy code.
  • When you want to take advantage of new technologies or languages.

I find that Mac OS X is a great example of how rewriting code can be a good thing. Rather than take OS 9 (which was a mature piece of software with a solid background) and turn out a new-and-improved version, they scrapped it instead. They rewrote things from the ground up. They ended up with a terrific operating system... my favorite, in fact.

[I'm adding this aside to recognize that OS X was built on some "old" code, specifically UNIX and NeXT. Although it was not written completely from scratch, I think it still exemplifies the point I am trying to make.]

Now there was a painful transition from OS 9 to OS X. For a while the best programs were not available for OS X. Users clung on to the last vestiges of OS 9. But over time, new software emerged. I think many Mac owners are now glad that they don't have to worry about "Classic" mode anymore.

Personally, I think that this is something that Windows could benefit from. They've taken many pages from Steve Jobs' book, why not this one too? A lot of the issues (especially security issues) in Windows linger because of backward compatibility. But a new OS would mean that old programs wouldn't work anymore. Microsoft, Windows programmers, and users would all have to take a leap of faith. But it can be done.

Another example is with some software my previous company was developing. We had some legacy AS2 / C code which was really just a nightmare to maintain, let alone improve. We looked at the situation and decided that we should take advantage of the new AS3 and rewrite. The new product turned out much better than the old one, both for the user and programmer. That's not to say it was perfect, but a definite improvement.

There are probably some other times when a total code rewrite would be beneficial. So certainly we shouldn't say never. But that decision needs to be made cautiously, with eyes open to the risks. If possible, keep up development on the previous version of the software.

I suppose that the moral of the story is that there is a time and season for all things -- even rewriting code from scratch.

Thursday, February 5, 2009

Read, Think, Write, Learn

In trying to be a conscientious, career-minded programmer, one of my goals has been to keep abreast of the goings-on in the programming world. Keeping current and learning new things is really vital for the overall success of a programmer. It keeps you relevant, it keeps you from being pigeon-holed, and it helps you stay interested in developing software, to name a few reasons.

In pursuit of that goal, in the last few months I've been looking for interesting blogs and sites that are relevant to my work. There are a few that I felt are worth mentioning. In fact, you'll notice that I've even gone as far as to add links on my sidebar! (Go ahead, look over there.)

The first one I want to mention is the excellent Grant Skinner's gBlog. I was first introduced to this blog sometime a year or so ago when I was doing a lot of Flash work. At the time we were having some problems with our application which turned out to be memory / garbage collection issues. Enter the gBlog. Mr. Skinner has some very helpful information out there about memory management in ActionScript 3 (AS3). Now I may have run across his site before, but this time it stuck. Useful information and really cool demos? That's a site to not forget.

More recently (in the last month or so), I've started following another blog called Coding Horror written by Jeff Atwood. I have found this blog to be very interesting. He has great writing style that practically compels me to read it and he covers some, dare I say, delectable topics. Plus he is working on a very cool site: Stack Overflow.

The thing that I love about these two blogs is that while I might not agree with everything they write, they cause me to think about stuff I care about. And that, my friends, is worth its weight in kilobytes.

Monday, February 2, 2009

Weekend Warrior

This weekend I was very industrious. My usual routine involves me helping my wife clean the house and then avoiding any other thing which resembles work. But this Saturday was different.

I fixed our leaking toilet by replacing the flapper. Although the toilet mechanism isn't terribly complex, I was still worried that I hadn't properly diagnosed the problem. But ever since installing the new flapper we haven't heard any more of the tell-tale running water.

I installed a programmable, digital thermostat. This was a bit more like rocket-science... or perhaps defusing a bomb? But the instructions were very clear and I didn't even electrocute myself. Within a few minutes time I had removed the hold and installed the new. Now we can actually tell what temperature it is set at instead of the old-fashoned guesswork. And it was easy to set up for our schedule. I'm hoping to see some savings in the utility bills this year.

I built some shelf additions for our DVDs. We have a deep bookcase which is deep enough for two rows of DVDs. Each shelf is also pretty tall, so I got the idea to raise the back layer of DVDs so we could see the back row. So while I was out buying the flapper and thermostat, I picked up some wood and got it cut right there at the store. I probably should have planned it a bit better and measured the wood I purchased, because when I got home I was miffed to discover that the wood was not the size it had claimed to be! I don't know if it was mislabeled or what. But I salvaged the operation and now we have our DVDs shelved in all their glory.

It felt good to get so much done around the house! Not that I necessarily want to abandon my typical ways, but now and then I enjoy a little weekend handiwork.