Ramblings of Narc

When the issue isn't confused enough.

ShittyCodeException

I’ve just had the immense pleasure of reading a bunch of code written by someone who is, or should be, a non-programmer.

Among other things, this piece of code (written in PHP) tends to take very roundabout routes to get where it’s going, its functions are mixed up with program logic (including such things as if(condition) function something() {};, which hurts my brain just thinking about it), and calls a Perl script to do something that’s eminently simple to do in PHP — querying a URL.

Thanks to an unattributed image found on Jeff Atwood’s blog, I can now express what the person writing this code should have been seeing as he wrote it:

Because that’s what was happening in my brain as I was reading it.

Now, I can appreciate code reuse, and the fact that the Perl script this one is calling is written mostly by myself gives me a nice ego-boost, but I’m questioning the validity of the current approach.

Firstly, what’s the point of having someone who is so obviously not a programmer write a bunch of code when I and my co-workers are generally available throughout the entire Toronto workday?

Secondly, does anyone doubt that this piece of code will end up having to be supported by us, the same people who should’ve been asked to write it in the first place? As evidence of this, I present the fact that I was the one asked to “fix it”. All I know is, at some point, I’m going to end up having to do some more in-depth maintenance on this code, and I’ll end up rewriting the whole thing, top to bottom. It’s just that bad.

And don’t even get me started on the excess trailing whitespace I just removed by saving the file. Or the shitty indentation that’s sometimes done with spaces, and other times with Tab. And even when done with spaces, it’s inconsistent between two spaces, three spaces and four.

I just noticed another thing: it calls mysql_free_result() at the very end of the application. How clever! It’s as if the “programmer” didn’t realize it would be done automatically the moment the script ended execution.

I’m also curious if the person who wrote this, ostensibly someone with the username “tony”, can even speak English. The reason I’m asking is this comment here: “Retrive Form Value and Assosate Vlaue for Xsell ID”.

Fun stuff, isn’t it?


3 Comments
  1. Felix Pleșoianu on 2009-01-20 at 22:01:58:

    Now, if this was TheDailyWTF, I would start with a “FRIST!!1!” comment, followed by “he should have used Javascript”. Oh wait, I just did. :P

    Seriously, this guy is a trained monkey. He can’t actually program, so the code is copy-pasted almost raw from a bunch of different sources. That explains the differences in indentation, the unmotivated call into Perl and pretty much every other problem you’re complaining about. As for his English, he probably lacks the brainpower to spell correctly…

  2. Narc on 2009-01-20 at 22:10:39:

    Your comment is very astute, especially considering I was just asked to “try to work with this guy”. And I did. And I’ve tried to tell him what’s wrong, but I’m operating at way too high a level of abstraction for him.

    The fun part: he’s been programming PHP for 3+ years, or so he says. He also says he “was in java++ and C+ once”. And he “[learned] PHP all by [himself]. did not go to school”. I was too dazed at the time of this revelation to consider the perfect reply: “Primary school?”

  3. Narc on 2009-01-21 at 00:59:01:

    On the other hand, I might be a masochist, but I actually enjoyed it, towards the end. The guy turns out to be reasonably good at debugging (at least, he was one step behind me all the way through), and he was profusely thankful for my help. He also admitted PHP isn’t his dream language (and maybe I picked up a hint of programming isn’t his dream job somewhere along the way).

    As for my part, now that I’ve worked with the code deeply, I know what I need to refactor when I end up fixing this code, so ‘sall good.

Add your comment

 

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