Friday, May 4, 2012

At Codeslingers last night, someone pulled out some coding Katas. For those who don’t know, a Kata is a coding exercise that is designed to practice your programming skills, rather than to solve a particular business problem. I was handed the classic “FizzBuzz” problem. The assignment:

Create a function that will print the integers from 1 to 100 with the following exceptions:

• If a number is divisible by 3, print the word “Fizz” in place of that number.
• If a number is divisible by 5, print the word “Buzz” in place of that number.
• If a number is divisible by both 3 and 5, print the word “FizzBuzz” in place of that number.

The output should look something like the following:

```1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16```

I started with a C# console application because that is the language with which I am most familiar. It was able to finish the following in under 2 minutes. It took me 5 minutes to write the unit tests.

```class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 100; i++)
{
var p = FizzBuzz(i);
Console.WriteLine(p);
}
}

protected static string FizzBuzz(int i)
{
if (i % 15 == 0)
return "FizzBuzz";
if (i % 3 == 0)
return "Fizz";
if (i % 5 == 0)
return "Buzz";
return i.ToString();
}
}```

I only occasionally code in JavaScript, so I tackled that language next. Someone recommended using http://jsfiddle.net/
as an online IDE for writing and sharing JavaScript, so I tried it and liked it. Of course, JavaScript is a dynamic language and one of my big challenges was spelling things correctly without all the help Visual Studio provides when writing in a statically-typed language. In my case, I misspelled the id of a div, which cost me at least 15 minutes. I created the following boilerplate HTML:

```<html>
<body>
<div id="fizzbuzz"></div>
</body>
</html>```

Then, I used the following JavaScript (plus a bit of jQuery) to output the FizzBuzz results:

```for (i = 1; i <= 100; i++) {
\$("#fizzbuzz").append(function() {
var newLine = i;
if (i % 3 === 0) {
newLine = "Fizz";
}
if (i % 5 === 0) {
newLine = "Buzz";
}
if (i % 15 === 0) {
newLine = "FizzBuzz";
}
var newDiv = \$("<div>").text(newLine);
return newDiv;
});
}```

A simple program like this provides a fun way to practice an old language and to learn a new language. Next up, I’ll try this program with F# and Ruby, since I have very little experience with these languages.

Friday, May 4, 2012 12:40:00 AM (GMT Daylight Time, UTC+01:00)
Saturday, July 14, 2012 8:46:16 AM (GMT Daylight Time, UTC+01:00)
RobI am not a big fan of behavioral quntisoes unless the person will be in a lead or manager role. For developers, if they do not appear to be arrogant or impersonal at all in the interview, you have a really good chance that behavior will not be an issue.It is surprising how few companies still do not look at existing code from a potential employee. I like the idea of having a code project with a specific deadline, like 2 days from receipt. That gives you an idea of what their code can look like without giving them tons of time to find a decent solution online.
Sunday, July 15, 2012 11:07:15 PM (GMT Daylight Time, UTC+01:00)