Tuesday, August 5, 2008

Speed or code clarity....?

Recently, I had a major dispute with one of my accomplices. I'm not at all going to sugar coat it - it was byuu, of BSNES fame, funnily enough.
Its quite funny how it started, then it turned immature...And guess what it is about: Code clarity or speed optimization. And code optimization is something I hold close to my heart.

Now, to understand the problem of this argument, you must first understand the differences in idealogy to each approach. Code clarity is about keeping code nice and simple, and easy to read. Code optimization is about trying to fit the same amount of work in less space, which means, less work for the CPU to do. We are talking about this in a emulation sense. And since both byuu and I believe speed hacks are the spawn of Satan, we are not, I repeat, NOT referring to anything that hinders accuracy.

Now then, there are several reasons why I prefer code optimization:
* Speed (well, duh) &
* Minimization or eradication of bloat, and not contributing to the "bloatware" problem in the IT society.

Now then, I have seen all too often how software over time has become more and more bloated. (a famous computer scientist noticed this pattern as early as 1995) And here is where one of the idealogies of byuu's and I's collide. I personally feel that we should make a effort to write code that is efficient and of as little bloat as possible. These days, we see operating systems, such as Windows Vista, and various PC games, taking up more CPU power, RAM, and HD space, than is really deemed worthy. By writing software that takes a non optimized approach, we are contributing to this problem, and make it more acceptable to make unefficient software. Which to me personally, is not. Add on top of that the ever more increasing advances in technologies and developers, can be sucked into not optimizing thier code, since, recent hardware can handle this. I personally find this utterly appauling. As developers, code should still be optimized. Not optimizing or taking little effort, to me, is a sin. Not to mention, even though I have 5-10 year hardware around that is still usable, I want my programs to run well on them. I hardly think then, relevance is even a good excuse to not optimize, as not optimizing, is just contributing to the bloatware issue.

Now, speed. To most people, speed is important. To me it is too. Having something optimized for speed, can certainly help with testing, as there is a wider possible user base. Which can be benificial in case. Not catering to a full crowd is quite underhanded, not to mention not nice. So speed optimization, to me is a important factor in how I code.

And as for code clarity when optimizing, there is such a thing as code commenting. I would have thought code commenting would have been a staple in documentation. So, I don't see how code optimization can be a issue, unless you are using really arcane optimizations to get a extra 10FPS. But still, you can comment on those optimizations explaining how they work.

So in conclusion my views are:
* Optimization should matter, not be a elective.
* Relevance is not really warranted. Code optimization code should be done, regardless of target hardware
* There is nothing wrong with commenting code
* We should not contribute to Wirth's law.