Code Kata: FizzBuzz–How did you fare?
In my last post, I introduced the concept of a code-kata (coding exercises) and gave an example problem to solve:
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
For those of you who tried the example, how did you find it? Pretty simple right?
Did you make it look this easy though? Whoever recorded that video is nicely demonstrating the benefits of honing their development environment – he/she even goes as far as disabling their mouse to train themselves to use the keyboard more effectively.
How well was your code designed? Is it adaptable to change?
Let’s move the goal posts
In real life, requirements change all the time. We can easily practice writing adaptable code by throwing some new requirements into the mix.
Try to take these steps one by one, as if a client was drip feeding them to you – try not to read ahead too far!
- Try extending the application to support another range of numbers, such as 15-175
- Try extending the application such that a user could provide any range of numbers (such as from the console, or from configuration)
- Try extending the application to support new rules – output “Baz” for numbers divisible by 4
- Instead of printing the numbers to the console, try extending the app to write to a file
Put your money where your mouth is, show me the codez!
Ok, my C# kata can be found on my github page here: https://github.com/CraigCav/FizzBuzz. Over time, perhaps we’ll see more implementations of this appear on my github page in other languages, such as F#. Interestingly enough, I used this example to hone my environment; to learn the GIT commands (instead of using a GUI) by practicing them over and over with this small simple example.