* This post is available at http://www.thinkcode.se/blog/2011/11/29/the-simplest-possible-solution*

## November 29, 2011

### The simplest possible solution

## 2 Comments »

RSS feed for comments on this post. TrackBack URI

* This post is available at http://www.thinkcode.se/blog/2011/11/29/the-simplest-possible-solution*

RSS feed for comments on this post. TrackBack URI

%d bloggers like this:

I’m a project manager with a programming background… And my question to you, what’s the point of creating a function that always returns a static number?

Comment by PM Hut — December 1, 2011 @ 09:34

There may be at least two reasons.

One being documentation. We want to avoid spreading magic numbers in the codebase.

Another is as a starting point for something that may become a complicated calculation. The answer for one specific situation may be the hardcoded number in the first iteration over the problem. The next time we we iterate over the problem, we may find that the static number isn’t sufficient and add some calculation. When adding the calculation we use the safety net from the first test to verify that we didn’t break anything. Hardcoding in this situation is the first step towards a general solution. If we need a general solution. I would expect the time between the first and second iteration to be measured on the second scale or the minute scale if we can determine early that a hardcoded value isn’t enough.

The point here is small and safe steps. It is easier to solve a small problem then solving a large problem. Large problems can always be divided into many smaller problems. A hardcoded number is a smaller problem then getting a complicated calculation right.

Comment by Thomas Sundberg — December 1, 2011 @ 09:50