3 ms·
> 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
by 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.