Tuesday, August 30, 2011

What The FizzBuzz?

So, I know that there are numerous blogs discussing the "FizzBuzz test" that is given to interviewees as a "weed-out" measure to eliminate bad programmers.  As an exercise in simplicity and timing, I have done a timed trial of implementing the program using Java as the programming language.  The environment used was Eclipse 3.7, which drastically reduces the time needed to complete the exercise as typing is much faster than writing code by hand.

Here is a sample of my code for the simple version:



This took me a total of 3 minutes and 50 seconds after opening Eclipse, but only 2 minutes and 48 seconds from the moment I started typing in the editor to the moment that I saved, compiled, and ran the program.  Now, to be honest this was my third time writing this particular program.  I have previously written it by hand, which took me over 4 minutes to write after first seeing the problem.  I was happy to say that my very first attempt at this problem was actually correct, albeit the algorithm was not quite so simple and had the redundancy of checking modulo 15 twice.  It was the first time I was actually timed when writing code and the experience was flustering to say the least.

After being exposed to a potential solution after my initial test, I decided to implement it at home so that I could play around with the JUnit testing aspect.  This exercise was not timed.  Below is the code I used for that brief exercise:



Also, here is the code for the test-file:



I chose not to fully document everything as it was a personal exercise out of curiosity.  I simply wanted to get my hands dirty experimenting with some JUnit tests.

So, why did I start out with a "time-trial" of such a simple program, when I have already become familiar with it?  Part of the reason is that I want to gain practice producing code "under pressure".  Another reason is to see how well my time had improved after becoming familiar with the problem, as well as the Eclipse Integrated Development Environment.  The fact that it was being timed also resulted in the simplistic code, not having any comments, and the absence of a method implementation approach for ease of testing.  Overall, this was a very simple exercise and I did not run into any obstacles with Java or Eclipse.  It was encouraging to see that my time had improved a little, which is to be expected after repetition.

Furthermore, I am well aware of the fact that all interviews are different and that practicing potential and otherwise trivial problems proves nothing of my capabilities as a software engineer.  I simply think that it is a good idea to practice in different areas.  As such, writing code against a clock is a good way to begin to think in terms of potential "crunch-time" scenarios were a solution needs to be generated as quickly as possible to solve a serious problem.  It is always ideal when given a problem to generate an elegant, well thought out, and creative solution.  Wisdom would dictate that not all scenarios are ideal and so it is a good idea to be prepared for situations which are not ideal.

No comments:

Post a Comment