News for hackers. Stuff that matters.
Re:FizzBuzz Enterprise Edition by developer1 on Sunday December 21, 2014 @04:50AM (#8779394)
I forgot to mention the variation where you start with an empty string, and % 3 to append 'Fizz' then % 5 to append 'Buzz'. This is also an instant pass in my book (two modulus, no calculation variables), though I don't personally care for the "coincidence" that for this specific problem the two conditions combined happen to provide the end result.

Then again it is FizzBuzz and not FizzBuzzMozz, where numbers divisible by both 3 and 5 produce a string that cannot be concatenated by the individual 3 and 5. So to be fair, this solution is perfectly valid. :p

Re:FizzBuzz Enterprise Edition by function_seven on Sunday December 21, 2014 @05:07AM (#8779417)
I know exactly what you mean by the "coincidence" and how taking advantage of it seems off somehow, but I suspect the original problem was written with that solution in mind.
Re:FizzBuzz Enterprise Edition by developer1 on Sunday December 21, 2014 @05:35AM (#8779442)
Other reasons that solution puts me off a little:

1. You have a dangling check for empty string at the end to set to the current number if the string is empty after the Fizz/Buzz conditions. An "else" clause disguised as an "if" clause.

2. It's just messier to understand. "If % 3, append Fizz; if % 5, append Buzz" has four different outcomes: neither matches, first matches, second matches, both match. A newcomer to the code has to mentally separate out all possibilities (which basically requires re-scanning the same code four times). Whereas the "if, elseif, elseif, else" can be read over and understood with a single scan.