Extendable And Adaptable Code That Will Stand The Test Of Time
All coders have heard the saying that the best code is highly cohesive and loosely coupled. It’s something so fundamental that all of us sometimes loose sight of this. Everybody has had a moment when you are refactoring old code and you just want to pull out a gun and ask your self, “Why?!? Why did you write it like that.” Along with laziness, its simply impossible to make external problems like time constraints, lack of personnel or dealing with users go away. But even in a perfect world, most of the code that you produce will be rewritten.
“If all code will be rewritten, then why write code at all?” you might ask. One answer is that you might get fired, but a more appropriate response is that for any program that you produce, it is also a lesson for producing the next iteration (if there is not another iteration, then you seriously did something wrong). What sucks about this view is that everything you do is merely practice for your next version or project. Of course this isn’t always valid when the code cannot be updated: embedded applications or software installed in an unreachable device (NASA - silly metric system). These cases are very rare and for most people, making changes is a server update or a patch away.
The reason I started thinking about writing long-term code is that working at Grooveshark, the underlying server code is being overhauled. But after the last couple of days, I started noticing that almost every other development group is also rewriting/refactoring a major portion of their code. Whether its Javascript, Java, PHP or SQL (maybe HTML/CSS?), the underlying principles are pretty much the same.
This problem has been discussed and worked on by acedemics and hackers much smarter than me so I really don’t have anything to add at the moment. Just go out there, make some mistakes and do better next time.