Monday, August 29, 2011

FizzBuzz in Eclipse


The FizzBuzz program is a fairly simple program in which numbers from 1 to 100 are printed out on successive lines, except in certain cases.  If the number is a multiple of 3, then “Fizz” is printed; if the number is a multiple of 5, then “Buzz” is printed; if the number is a multiple of both 3 and 5, then “FizzBuzz” is printed.
In total, I took nine minutes and fifteen seconds (9:15.88) to implement the FizzBuzz project in Eclipse.  I do not have any standard of comparison for this, but I think that this is an unreasonably long time for such a simple program. 
In my defense, I spent a great deal of time attempting to make the stylistic changes that eclipse-cs (from my previous entry) suggested.  These changes primarily included moving braces onto preceding lines and putting spaces around operators.  I admit that this is a weakness of mine, and I shall be working on breaking this habit.  However, eclipse-cs provided some warnings that I do not know how to respond to.  For example, my code includes the following:

 
This is the standard main method definition; in fact, I had Eclipse create the method for me, removing the potential risk of human error.  However, eclipse-cs still produced the warning: “Expected @param tag for args.”  This would be a perfectly valid warning, except that the @param tag is two lines above the method definition. 
Some of the warnings that eclipse-cs provide are also too vague to be of use.  The closing braces for the if and else-if statements all have the warnings “’}’ should be on the same line.”  This message gives no suggestions as to what line the brace should actually be on.   
Aside from the warnings that eclipse-cs produced, I did not experience any problems while implementing the FizzBuzz program.  Writing the FizzBuzz program in Java less than a week ago may have been a factor in the lack of errors.  I also have some limited experience with Eclipse; though I cannot do anything more sophisticated than create new projects or files and run applications in Eclipse, the FizzBuzz program fortunately does not ask for more than that. 
At least at the moment, setting up the project and adjusting to match the suggested style seem to have taken up most of the time used to create a project.  I would estimate that writing the actual program took only three or four minutes at the most.  However, the time necessary to edit the code to match coding standards should be greatly reduced once I become more familiar with the standards. 
The code for the FizzBuzz program is provided below.

No comments:

Post a Comment