The Daily WTF
David was poking around in some code for a visualization library his team uses. It’s a pretty potent tool, with good code quality. While skimming the code, though, David found this mismatched comment and code:
def get_tip(self): # Returns the position of the seventh point in the path, which is the tip. if config[“renderer”] == “opengl”: return self.points[34] return self.points[28] # = 7*4
Now, I’m going to set aside the issues of stringly typed fields (at least use a constant or an enum), or magic numbers (again, the constant). What I want to highlight is what David saw: neither 34 nor 28 are seven. It’s inaccurate and misleading to refer to either of those as the seventh point in the path. If nothing else, it’s confusing. But I don’t think it’s wrong, or at least, the wrong-ness isn’t actually in this code.
Without broader context, I don’t know
To read the full article click on the 'post' link at the top.