Kijana Woodard

Software Minimalism


FizzBuzz++

Sunday, May 9, 2010

Thanks to Matt Taylor sending me email comments about my Avoiding FizzBuzz post, I decided to jazz it up a bit.

This whole blog is dedicated to avoiding FizzBuzz type questions in general, so I figure the more code posts the better.

Using my IEnumerable Each extension method, I tried out this version of FizzBuzz:

Action<int> printnum = num =>
{
    var value = num % 15 == 0 ? "FizzBuzz"
              : num % 5 == 0 ? "Buzz"
              : num % 3 == 0 ? "Fizz"
              : num.ToString();

    Console.WriteLine(value);
};

Enumerable.Range(1, 100).Each(printnum);

Notice I’m still trying to decompose statements into rough single responsibility. I’m still going for readability/maintainability over trying to minimize statement count. At the same time, I always strive to reduce typing by staying pretty DRY. It’s a balancing act.

Thoughts?



If you see a mistake in the post *or* you want to make a comment, please submit an edit.

You can also contact me and I'll post the comment.

3 Comments...
Larry
Larry • 7 years ago

My biggest pet peeve is people who post code do not include the using/imports required to cut/paste/run the snippet! I'm lazy!

kijana
kijana • 7 years ago

Haha. I didn't post them because I didn't write them. Wrote it all in one file. I'm lazier!

Paste into static Main of your choice.