Tuesday, August 31, 2010

Open Source Software Experience

Sourceforge is an online repository for open source applications.  In this post, I will describe my experiences in downloading, installing, and using an open source software system.

Overview
The program that I downloaded is called JConvert, and can be found at https://sourceforge.net/projects/jconvert/.  It is a unit conversion program that provides a simple and easy-to-use GUI.


Prime Directive #1 -
The system successfully accomplishes a useful task
JConvert satisfies Prime Directive #1.  It features a plethora of unit conversions that are useful in the fields of physics, chemistry, math, computer science, and engineering.

Prime Directive #2 - An external user can successfully install and use the system
JConvert satisfies Prime Directive #2.  The program is packaged as an executable jar file called "jconvert-1.0.9.jar" that only needs to be double-clicked to run.  As shown in the first image above, I was able to obtain an accurate conversion from 1 megabyte to 1024 kilobytes.


Prime Directive #3 - An external developer can successfully understand and enhance the system
JConvert partially satisfies Prime Directive #3.  The author provided another site http://jconvert.sourceforge.net/howto.html and specific details on how to modify and add your own conversions to the program.  Javadoc files were also included.

However, the author did not make source code readily available as the executable was packaged as a .jar file.  I extracted the contents of the .jar file as shown below


Furthermore, the source files were all in .class format.  The only way to see the actual source code was to decompile the .class files.  I proceeded to download and use a nifty Java decompiler from http://java.decompiler.free.fr/.


The major drawback is that in-line documentation and comments cannot be restored from decompiling a .class file.  Despite these difficulties, a developer would be able to understand and enhance the system by using a decompiler and the Javadoc files provided on the author's site (although with significant effort).

Monday, August 30, 2010

FizzBuzz Program

The FizzBuzz program is a simple test that is used often by employers to root out those who can actually program and those who can't.  On paper, I was able to implement FizzBuzz in about 3 minutes without proper documentation and comments.  Using Eclipse, it took me about 10 minutes as I fiddled around in my new IDE.

/**
 * Prints out all numbers from 1 to 100, except "Fizz" is printed when it is a   
 * multiple of 3, "Buzz" is printed when it is a multiple of 5, and "FizzBuzz" 
 * when it is a multiple of both 3 and 5.
 *
 * @author David Lin
 * @date August 30, 2010
 */
public class FizzBuzz {
  /*
   * @param args ignored
   */
  public static void main(String[] args) {
    for (int i = 1; i < 101; i++) {
      if (i % 15 == 0) {
        System.out.println("FizzBuzz");
      }
      else if (i % 3 == 0) {
        System.out.println("Fizz");
      }
      else if (i % 5 == 0) {
        System.out.println("Buzz");
      }
      else {
        System.out.println(i);
      }
    }
  }
}

The first problem I encountered was that Eclipse defaulted to tabs for indentation.  The standard for this Software Engineering class is 2 spaces.  I used the search function in Eclipse's help library, but it was fruitless, so I searched "Eclipse how to change indentation" on Google.  I found a posting on stackoverflow.com that indicated the location of this setting, which is Windows > Preferences > Java > Code Style > Formatter > Edit > Indentation.  I also learned of a quick way to have Eclipse automatically reformat my code with the new settings, which is Ctrl-Shift-F.

The second problem I encountered was formatting my FizzBuzz code to show up nicely in this blog.  A quick and easy way to retain coloring and formatting is to
  1. Copy the code from Eclipse
  2. Paste into Word
  3. Copy from Word and paste
This experience has taught me that standards (indentation), clarity (documentation, formatting), and resourcefulness (problem-solving) are important in software engineering and this class in general.