The Difference between a Professional and a Duffer

By the time I post this story it will be long in the past. I was called in to help another programmer. His code was a semblance of the first set of code. Every time DO X ran with something that did not work, the rest of the program was not run, it failed.

Bad:

SET Z = $1

FOR i in X Y

DO X
  sometimes this works, if it doesn't fail badly
END DO

DO Y
  IF Z == TEST1
    do something
END DO  

This was his re-write, better, but not good. Do you see the difference? At least this time everything else in the program is run first, then the program runs the failing code every time, regardless.

SET Z = $1

FOR i in X Y

DO Y
  IF Z == TEST1
    do something
END DO  

DO X
  sometimes this works, if it doesn't fail badly
END DO

Under the circumstances the best option. This section that fails will only run if everything has not triggered.

SET Z = $1

FOR i in Y

DO Y
  IF Z == TEST1
    do something
  ELSIF Z == TEST2
    do something else
  ELSE
    sometimes this works, if it doesn't fail badly
END DO  

If you recognize the difference in this logic I commend you, my co-worker did not and put it into production. It’s the small logic puzzles that we should enjoy.

 

This entry was posted in Code, Thoughts. Bookmark the permalink.

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