Monday 8 March 2010

Interesting numbers…

I was looking through a post on Reddit discussing reality of learning programming in 21 days, as illustrated by this site (and taken a little more seriously here), when I stumbled across an extremely interesting article What your computer does while you wait by Gustavo Duarte.

If you’re interested in such things this makes a very informative read.

To take a sentence out of this article, whilst talking about how fast instructions are to process on a modern CPU Gustavo makes this comment:

It’s worth keeping this in mind when you’re thinking of optimization - instructions are comically cheap to execute nowadays.

In case you miss it, later on in the comments section he makes the point that should go hand-in-hand with this one:

99% of the time you want the cleanest, simplest code you can possible write. In a few hotspots, which you discover by PROFILING the code rather than guessing, you optimize for performance if it’s really called for.

Everything I’m reading at the moment points in the same direction, basically that software is so complex and code bases so large that it needs to be written to primarily be understood, or as Martin Fowler puts it in his book Refactoring: Improving the Design of Existing Code:

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

Amen to that.

One of the points Martin makes is that be refactoring you often don’t make the the code any slower as, by the process of making the code more understandable, you can optimize the code more easily, possibly even as a side product of the refactoring. Even if this is not the case, after the refactor the code is easier to optimize in those areas where this is really needed.

So that’s going to be my mantra outside of the workplace from now on (and inside the workplace where I can, but I’ll describe that as much as I’m allowed to in a later article). In fact, that’s been one of my strong points to a greater or lesser degree since I started out, I try to follow the KISS principle:

Keep It Simple, Stupid!

I’m the stupid part. If you let me keep it simple I’ll write you something that’s useful (but often in the real world we’re thrown into overly complex existing systems that we have to code to without any chance of being able to influence the overall design in a positive direction). Or, to paraphrase Martin Fowler again (since I can’t locate the quote): I’m not a great programmer, I’m a good programmer with great processes.

Just give me the framework that allows this, or allow me to create one, and we’ll all be happy.

No comments:

Post a Comment