In my line of work, I frequently see code written by many different programmers. There's nothing like looking at someone else's code to make you notice new code smells. One that popped up up the other day was a method that contained an early return that returned an empty string. The strange thing about this is that the method itself didn't return an empty string - it returned self. Generally, you don't want a method to return inconsistent return types. It makes the calling code work harder to interpret the return value. If the method returns a string, every way of returning from the method should return a string. Similarly, if the method returns self, every return statement in it should return self or an object that's interoperable with self. In this particular case, the return value was never actually used, so I guessed that the programmer meant to just exit the method and a return self would have worked just fine.
Download