Thomas Sundberg

November 29, 2011

The simplest possible solution

Filed under: Agile, Clean Code, Java, Programming, Software Craftsmanship, TDD, Teaching — Tags: , — Thomas Sundberg @ 22:02

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

Advertisements

2 Comments »

  1. 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


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: