Geeks With Blogs
My Blog geek yapping
Computer Locke

In the show LOST, the Swan Station had a button that “had to be pushed” every 100 minutes to avoid disaster.  Several characters in the show took it upon themselves to have faith and religiously push the button, resetting the clock and averting the unknown “disaster”.  There are striking similarities in this story to the code we write every day.  Here are some common ones that I encounter:

  • “I don’t know what it does but the application doesn’t work without it”
  • “I added that code because I saw it in other similar places, I didn’t understand it, but thought it was necessary.” (for consistency, or to make things “work”)
  • “An error message recommended it”
  • “I copied that code” (and didn’t look at what it was doing)
  • “It was suggested in a forum online and it fixed my problem so I left it”

In all of these cases we haven’t done our due diligence to understand what the code we are writing is actually doing.  In the rush to get things done it seems like we’re willing to push any button (add any line of code) just to get our desired result and move on.  All of the above explanations are common things we encounter, and are valid ways to work through a problem we have, but when we find a solution to a task we are working on (whether a bug or a feature), we should take a moment to reflect on what we don’t understand.  Remove what isn’t necessary, comprehend and simplify what is. 

Why is it detrimental to commit code we don’t understand?

  • Perpetuates unnecessary code
    • If you copy code that isn’t necessary, someone else is more likely to do so, especially peers
  • Perpetuates tech debt
    • Adding unnecessary code leads to extra code that must be understood, maintained and eventually cleaned up in longer lived projects
    • Tech debt begets tech debt as other developers copy or use this code as guidelines in similar situations
  • Increases maintenance
    • How do we know the code is simplified if we don’t understand it?
  • Perpetuates a lack of ownership
    • Makes it seem ok to commit anything so long as it “gets the job done”
  • Perpetuates the notion that programming is magic
    • If we don’t take the time to understand every line of code we add, then we are contributing to the notion that it is simply enough to make the code work, regardless of how.

TLDR

Don’t commit code that you don’t understand, take the time to understand it, simplify it and then commit it!

Posted on Wednesday, April 11, 2012 2:44 PM | Back to top


Comments on this post: Programming doesn’t have to be Magic

# re: Programming doesn’t have to be Magic
Requesting Gravatar...
Great article. I'd like to hear what you have to say about the single motivation for notorious copy-pasters like myself: FEAR.

I'm afraid of the unknown amount of time it might take to truly understand what a particular piece of code is doing. Will it take a couple minutes? Will it take hours of writing hello world samples? In the end, I would rather just slap in some arbitrary code containing the "magic sauce", rather than risk spending an untold amount of time understanding what's happening, because it has the potential to make me look bad in the eyes of my peers and employer.

This is however, a poor excuse for not understanding the tools we are wielding. (Can you imagine allowing your car mechanic to say, "I don't know how it works, but that piece of scotch-tape right there makes your car work again. Have a nice day.")

So, what do you have to say about fear of the unknown, and fear of looking bad in front of your peers?
Left by Darth Ragsdale on Apr 17, 2012 11:58 AM

# re: Programming doesn’t have to be Magic
Requesting Gravatar...
Understandable, I would suggest incrementally learning a bit more each time you use something, that way if it's something you tend to copy/paste a lot, you will learn more about it and become more comfortable with it. Only invest a couple minutes and see where it leads you. Also, I'd try to find the original author and use them as a source to expedite your learning experience if possible.

Fear left unaddressed will only compound to greater fears in the future, find a way to incrementally address it, maybe not all at once :)
Left by Wes on Apr 19, 2012 6:14 PM

Your comment:
 (will show your gravatar)


Copyright © Wes McClure | Powered by: GeeksWithBlogs.net