What Shape Should My Code Take? (using FizzBuzz)
Sometime back in my early days of programming, I learned to enjoy a truth table. Fizzbuzz seems to beg for a simple truth table - the values ' should_fizz ', and ' should_buzz ' form up a simple tuple of booleans, and the choices are True, False - fizz False, True - buzz True, True - fizzbuzz False, False - string of the number This expresses rather neatly in Python, is efficient and pythonic, and handles negative cases neatly also: But here's the rub: One of the "normal" changes is to add a rule that multiples of 7 say 'woof' even if they are also divisible by 3 or 5. That's a peculiar rule, but let's consider it for a moment. If I am going to add another term to the set, I have to edit the match line and every case line. I will have to add new cases for all the possible truth values in my new 3-tuple table. That's not so much fun. The changes to my test suite are, at least, minimal. The best expression in our codebase may not be t...