License to Code

As a software engineer I don’t often find myself in scary or life threatening situations – at least not as a direct consequence of my career choice.

Not too long ago, however, I was working on a customer project in which some core functions were lifted from a previous version of the same product. I was told to just re-use what was already there – no point in re-inventing the wheel, right?

As it turned out, the old code was not really doing what it should. This was not a revelation per-se, pretty much all code has some bug or another if you dig deep enough, but the one I found was sufficiently odd to cause me to dig a bit deeper.

Eventually it led me to this (names has been changed to protect the innocent):

private void calc(int x, int y, String sl, String l)
  ArrayList<Obj> list = new ArrayList<Obj>();
  list.add(new Obj(14.29,70,0));
  list.add(new Obj(10.53,95,0));
  list.add(new Obj(8.33,120,0));
  list.add(new Obj(6.90,145,0));
  list.add(new Obj(11.11,70,20));
  list.add(new Obj(8.70,95,20));
  list.add(new Obj(7.14,120,20));
  list.add(new Obj(6.06,145,20));
  list.add(new Obj(10.00,70,30));
  list.add(new Obj(8.00,95,30));
  list.add(new Obj(6.67,120,30));
  list.add(new Obj(5.71,145,30));
  list.add(new Obj(9.09,70,40));
  list.add(new Obj(7.41,95,40));
  list.add(new Obj(6.25,120,40));
  list.add(new Obj(5.41,145,40));
  list.add(new Obj(8.33,70,50));
  list.add(new Obj(6.90,95,50));
  list.add(new Obj(5.88,120,50));
  list.add(new Obj(5.13,145,50));
  list.add(new Obj(7.69,70,60));
  list.add(new Obj(6.45,95,60));
  list.add(new Obj(5.56,120,60));
  list.add(new Obj(4.88,145,60));

  for(Obj obj : list)
    if(obj.getX() == x && obj.getY() == y)
      Double answer = 
        obj.getValue() * Double.parseDouble(sl) * Double.parseDouble(l);

I did not include the source for Obj because it doesn’t really matter, so I’ll spare you the time to review what this does and just spell it out for you:

answer = sl*l*(1000/(x+y))

If someone had presented me with this out of context, I would have assumed it was a joke, but it’s not. It’s actual production code from a real-world application, and it’s just wrong on so many levels that I’m not even going to bother dissecting it.

Instead, I’d like to return to the part about my job not being scary or life threatening.

In this case the application was benign and, although stupid, the code did (almost) what it should (round-off errors aside), but seeing this piece of code, and realising that there are actually people out there who call them selves “programmers” or “engineers” who’d do something like that, it occurred to me how ridiculously dangerous bad programmers are.

It’s not just about wasting time, or being annoying, but who is to say that this person won’t end up working for the bank that looks after my money? Or some company that writes control code for nuclear submarines?

Considering that I’m hardly allowed to install a lightbulb in my own home without a license, it’s downright scary that people are allowed to work on software when they have no clue, let alone a license.

Leave a Reply

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

You are commenting using your 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