4 ms·
I had one interview a few years ago when I had to solve FizzBuzz in a TDD way; I realised quite quickly that to solve the problem as described with TDD resulted
by andrewingram 5y ago
I had one interview a few years ago when I had to solve FizzBuzz in a TDD way; I realised quite quickly that to solve the problem as described with TDD resulted in a more complicated solution, including things like changing the API to allow me to inject a "printer" so that the test could pass a double instead.
Still a very easy problem, but the irony of TDD making FizzBuzz harder made me smile.
- e12e 5y ago> including things like changing the API to allow me to inject a "printer" so that the test could pass a double instead. In what language? Isn't the basic case of fizzbuzz a procedure/function that takes a number and returns a string (if you are strongly typed, not able/willing to return a complex type)? Printing and reading input would be side-effects, surely? (so you plug the input to your fizzbuzz, and the output to a stream, maybe via a formater?)
- dagw 5y agoThe only formulation for FizzBuzz that I've seen 'in the wild' is "Write a program that prints XYZ (to standard out)"
- e12e 5y agoI don't think treating it as two subproblems: generate a sequence xyz, print the sequence to standard out - is terrible over-engineering - especially if it enables simpler tests? Ed: or in the case of fizz-buzz; a function to transform a number (returns "<number>", "fizz", "buzz" or "fizz-buzz"), a function that maps a sequence (eg 1..100) via fizbuzz(), and then a function that prints such a sequence.
- andrewingram 5y agoAs in dagw's reply. The question as posed to me has always asked to write code that prints to stdout.