I had an insidious idea at work yesterday. Sometimes you generate two different statistics, but due to the way you calculated the numbers, it makes absolutely no sense at all to, say, add the two numbers together. It might be tempting to add them because the sum
looks like the right answer, but it's not in the general case. Comments highlighting this truth are easily ignored, so I briefly considered implementing something like this:
class Value(int):
def __add__(self, other):
raise TypeError('unsupported operation +')
Python will even let you shadow the int type (i.e. replace Value above with int) and then you can really confuse anyone reading your code.
My conscience got the better of me and I didn't do this.
No comments:
Post a Comment