Simberon Design Minute
 

Side Effects

I was debugging a problem recently where widget sizes weren't being calculated properly on a user interface. I knew that the reason for this was that certain instance variables weren't being set properly before the widget was being displayed. When I traced down what methods did set those instance variables, it showed only one method called preferredExtent. To me, the name preferredExtent would apply to a method that does some sort of calculation and returns you the answer. In this case, it did do calculations but it also set various instance variables before returning the answer. This is a strange side effect to a method that should only calculate. When you read code, you expect that the methods do what the names indicate and side effects like this are difficult to understand. Consider naming the method something better that indicates the intent or move the setting of those variables to another method that's explicitly designed to do so.

Download