How to justify anything as a developer

One way of calculating pi is from the area of a circle, you could even embedded that image in the code. You /could/ then suggest someone call this as an external program, to calculate pi from a script. This is clearly a stupid thing to do.

Here’s a badly written program to do it:

#include <stdio.h>
#include <math.h>

char mask [20][20] = {

// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
  {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
  {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
  {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
  {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
  {0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
  {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

};


int main() {

  int area=0;

  for(int x=0;x<20;x++) {
    for(int y=0;y<20;y++) {
      if(mask[x][y] == 1) area++;
    }
  }

  printf("pi: %f\n",(float)area/((17/2)*(17/2)));
}

And here are some ways of justifying it:

Hmm perhaps we should refactor this, maybe there’s a better way?
It works so it’s fine, there are more important things for us to be working on.

Why don’t you just use a hardcoded value, or value from a library?
That’s crazy, you should /always/ avoid magic numbers in your code. How do you know a hardcoded value is correct? You’re developers get no intuitive feeling for the value of pi. They don’t know how to increase the precision of the value. I’m sorry that’s just nuts.

The answer is WRONG it calculates pi as around 3.7
There’s no /right/ answer, all values of pi are approximations. 3.7 is good enough for many applications. It’s also trivial to modify this program to use larger circles and get a better approximation.

OK, but there are FASTER ways of calculating pi
Have you benchmarked it? (people are generally too lazy to benchmark). If it’s really a performance bottleneck you can calculate the value once and store it. In any case, don’t be sucked into premature optimisation. Developer time is more expensive than compute time.

But it’s completely UNCLEAR
I disagree, this method gives the developer a visual representaion of the value of pi. They can intuatively see where the value is coming from. What’s more it’s easy from them to change to code and add larger circle images as required. There are even peer reviewed images of circles all over the Internet which can easily be incorporated.

You’re nuts
You just don’t understand the business case for doing it this way, you’re too wrapped up in the technical issues to see the big picture. You’ll understand better when you’ve been programming for (as long|at the same scale|with large teams) as me.

You can attempt to justify pretty much any programming position by appealing to: utility, premature optimisation, readability and intuition, business cases, and the old standby: experience.

One thought on “How to justify anything as a developer

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>