Developing Your Programmer’s Intuition

The other day I solved a bug. I didn’t think much of it. The bug basically manifested itself when the user search for data but none was returned. We write an ‘enterprise-grade’ software application, so there is a lot of code and tiers between clicking the search button and displaying the data in the client. But in thinking about this bug I had pin pointed only a few methods in a few classes. The problem ended up being that in the database there was a value that was padded with an extra white space and one of the SQL queries used returned an empty set. I didn’t think much about the fix to the bug, but when I described the problem and solution to my coworker he said, ‘How did you know there was an extra whitespace? I would never have thought of that, you can’t tell if there is a white space by just doing a select.”

I think that as software programmers, we do develop of certain intuition that allows us to better understand software. This code sixth sense aids us in debugging, problem solving, and trouble shooting your own code, as well as third party applications. After seeing soo many null pointer and cast class exceptions, you develop a noise for sniffing out smelly code.

Here are a short list of root causes for stupid bugs I have encountered. I have seen bugs in hash maps because the key is case sensitive. I have seen a lot of problem when trying to parse a file extension type and someone uses the String’s indexOf (use lastIndexOf instead). You are comparing the equality of a string against a string literal, code defensively to avoid null pointer exceptions (“LITERAL”.equals(stringVariable)). Encapsulation means nothing if you provide a public getter and setter for every field for every class. Code against interfaces. Objects that are are globally cached should be immutable. Runaway memory leaks are caused by maps that cache large objects that are not removed. In batch files, you need to quote paths if they have spaces.

If you are a novice programmer you can read into smelly code and try to write effective code to develop your programmer’s intuition. Programmer’s intuition is developed through experience.

Technorati Tags: , , , , ,

Related posts:

  1. Top Programmers on Twitter to Follow
  2. The Programmers Kindle Book Club
  3. Developing a Real-World Web Application with NetBeans 5.5 Visual Web Pack
  4. Debugging Users and Invisible Characters
  5. It’s Always Your Problem
  6. Worst Software Bugs


Leave a Reply