Don’t trust third party products

Some weeks ago @marcellhegedus and myself were doing a major refactoring on our code base. It took us long days, and we finally managed to get the code into a good shape. We split functions, extracted new classes, renamed methods and variables, deleted unused code. Besides cleaning out the code, we even made some optimizations to it. That optimization involved changing some of the API calls, so we didn’t have to read the database every time for every single piece of data. We found out that the API could check it directly whether an external object has a certain parameter or not, without reading its actual value. It was a nice and elegant shortcut that made that component reasonably faster.

The parameter I’m talking about is used for displaying some tiny icons on the GUI. The presence/absence of that parameter makes the difference whether different list items are displayed with a green or a gray icon. The presence of the parameter indicates green icon, the absence of it -you’ll be surprised- red icon (I told you you’d be…)

To tell the truth, I was very proud of these changes. We followed a lot of best practices and I finally felt we did the right thing and did it the right way. When I integrated the modifications I even added a long description how these things will magically make our life better, faster and easier.

However, it didn’t take too long until some colleagues started complaining about the system.  “All the list items are displayed with green icons, it’s really strange”, they said. So we started a long, long (I mean it) long debug process. We debugged everything. All the code was full of breakpoints, variable watches, expression evaluations and every single thing that could help us debugging the code. Four of us were troubleshooting all kinds of low-level methods. After several days, we got completely confused: all the methods were checked several times and everything seemed to be working OK. It was really annoying; all our code was looking good, but the system was still dysfunctional. And that was the point, when one of our colleagues looked into an API call. The method was called getParameter(parameterName); you just pass in a parameter name, and get back the value of that parameter. You can guess how amazed we all were when the implementation of the method was something like this:

public String getParameter(String parameterName) {

   parameterValue = lookTheValueUpSomehow(...)
   if (parameterValue == null) {
    // create that parameter
    parameterValue = "";
   return parameterValue;

That is the last thing I’d expect from a getter: to be creating things. This whole thing would have been avoided if the method had been named something like getOrCreateParameter. At the end it turned out that there was another method for reading the parameter’s value, but that method name was also kind of misleading.

Actually, this was the last time I trusted a method name. We cannot be careful enough. I wonder how we could have solved the problem if we hadn’t had access to the API’s source code… Anyway, it’s nice that we didn’t have to fall back to the initial solution.


Author: tamasgyorfi

Senior software engineer, certified enterprise architect and certified Scrum master. Feel free to connect on Twitter: @tamasgyorfi

1 thought on “Don’t trust third party products”

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