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.

Saturday, August 27, 2011

eclipse-cs

eclipse-cs
By itself, Eclipse checks code for syntactical errors.  This ensures that the code is free of errors that would prevent the program from running; in other words, the Java Virtual Machine can read the compiled application.  However, while the computer may be able to understand this code, there is no guarantee that any human will be able to comprehend the code.  For this reason, there exist several different standards and guidelines that instruct programmers in how to write code.
Naturally, if programmers do not use these standards, then the standards have no value.  To ensure compliance with these stylistic rules, an open source tool called Checkstyle examines Java code to ensure that the code complies with a particular coding style.  Eclipse-cs is a plug-in for Eclipse that incorporates Checkstyle into the development environment.  This allows the programmer to receive immediate feedback on whether his or her code fits with the expected coding standards.
Eclipse-cs is available for download at http://sourceforge.net/projects/eclipse-cs/, and the project site is http://eclipse-cs.sourceforge.net/.

Prime Directive 1: The system successfully accomplishes a useful task. 
As claimed, eclipse-cs checks Java code for stylistic errors and flags them as warnings.  Eclipse-cs updates this list of warnings every time that the user saves a file.  This does mean that the list is not automatically updated, in contrast to the syntax errors that Eclipse immediately recognizes.  However, since files must be saved before they can be compiled or tested, the user will have to have the list updated before he or she can use the code in question. 
Eclipse-cs also allows users to create their own coding standards.  This function is useful primarily for project managers or administrators who wish to establish a particular standard.  Indeed, without the ability to define what rules eclipse-cs should run under, the plug-in would be nearly useless, as users would be confined to only what the default standards require. 
An example of eclipse-cs in action is in the screenshot at the end of this entry.  The lines highlighted in the code include some sort of style error. 

Prime Directive 2: An external user can successfully install and use the system.
Since eclipse-cs is an Eclipse plug-in, it is installed in the same manner as any other new software for Eclipse would be.  However, this was not made clear on the download page at SourceForge.  Instead, it appeared that it would be necessary to directly download the files for eclipse-cs and then uncompress them in some directory; while this is actually one method of installing eclipse-cs, it is not the recommended method that the project site suggests.  Once installed though, eclipse-cs is extremely easy to use for the purpose of ensuring that code meets standards, as the user does not have to do anything other than write code and respond to the warnings that eclipse-cs provides.   

Prime Directive 3: An external developer can successfully understand and enhance the system.
Eclipse-cs is open-source, with the code available for examination at SourceForge.  Actually understanding this code can be slightly more difficult, if only for the sheer volume of information.  The lack of any readily available documentation aside from the comments in the code also increases the difficulty of understanding the code.  The forums at SourceForge would presumably offer some assistance in understanding the code, though they seem oriented more towards the utilization of the code rather than its development.