Sunday, August 31, 2008

O.S.S. Experience - iPodCopy

Purpose:

To evaluate an open-source software and see how well it meets the Three Prime Directives from the end user's perspective. The open source software I will be evaluating is iPodCopy.

Overview:

iPodCopy is an Java application that allows users to copy mp3s from your iPod to your PC.

Download Link: iPodCopy. (note: src-zip file is missing a .jar file needed. The missing .jar file can be found in the bin-zip file.)


Prime Directive #1 - Useful Task: PASS

iPodCopy accomplishes a simple yet important task that Apple's iTunes fails to deliver. iTunes only allows single direction file transfers from the computers to the iPods. This may be to protect illegal distribution of songs. However often times, users delete all or most of their mp3 files for various reasons (system format, open up disk space, etc) without backing them up. The only way to recover these files are to purchase and download the mp3s all over again. iPodCopy solves this issue and allows users to recover mp3s from their iPods to their computers.

Prime Directive #2 - Successful Install and Use: PASS

iPodCopy is a stand-alone program with no installer. As the user, I only needed to extract it to a location and open the program launcher, iPodCopy.exe. In some aspects, it failed this Prime Directive I suppose. Because my purpose was to download, use, AND look at source code, I needed the src-zip. However, a crucial .jar file was missing to run the program. The file was included in the bin-zip file though.

Performance-wise, iPodCopy easily does its job. The user interface is simple yet effective (shown above). It has a familiar feel and appearance to Apple iTunes. iPodCopy also features a nice search bar similar to that of iTunes to quickly search through mp3s.

Prime Directive #3 - Ability to Enhance: FAIL

iPodCopy fails to achieve this directive. It does provide it's source code and uses meaningful method names. However, there was no line of comment or any form of documentation anywhere. To even guess at what each class or method does, external developers would need to trace the code between 20+ classes or guess according to the method names.

The format the developer writes seems readable. If only the original developer included some sort of documentation, I would believe this is something external developers can add to. To edit or add to this project, external developers likely need to read every single line of code themselves.

Tuesday, August 26, 2008

FizzBuzz

About FizzBuzz:

FizzBuzz is an application that prints the numbers 1 to 100 each on a separate line. However if any of the following conditions are met, then an alternate string will be printed.
  • If the number is a multiple of both 3 and 5, then "FizzBuzz" is printed instead.
  • If the number is only a multiple of 3, then "Fizz" is printed instead.
  • If the number is only a multiple of 5, then "Buzz" is printed instead
Purpose:

FizzBuzz is not a useful program. Instead it's purpose was to see how fast we, the students, could write code for a simple program such as FizzBuzz. In addition to noticing our efficiency, we also got introduced to Eclipse IDE, a powerful Java editor that is better than "sucky ol' notepad" as Dr. Johnson put it.


The Development Process:

Arriving at the algorithm for FizzBuzz was not the time-consuming part. It was getting familiar with Eclipse and learning about JUnit Test Case that took some time. I have never written a JUnit Test Case before. Prior to JUnit Test Cases, I was simply using System.out.println() inside my code to debug and test my cases.
In this JUnit Test Case, we used assertEquals to explicitly state what the correct output should be and compared it to the actual output produced by our code.

Main problem(s) that I've encountered:
  1. Learning how to setup JUnit Test Case.
  2. Changing indentation size in Eclipse.
How the problem(s) was solved:
  1. With some review from the notes I took in class and googling, I found what I needed to import to have everything working. I also noticed Eclipse had a suggestion for what to import. I should have checked there first.
  2. I played around with some of the settings until I finally found it. Under Window | Preferences | Java | Code Style | Formatter... and creating a new profile to match my text editing needs.
Total Time for Completion:

25 mins

What I Learned:

I wasn't too concerned with test cases failing this time because of the simplicity of FizzBuzz. But I can imagine I need to be more cautious when writing long pieces of code. JUnit can save time and effort, quickly testing cases without altering the innards of the actual functions unless necessary.

Through this exercise, I gained some experience with Eclipse. I still have much to learn about Eclipse. But so far, I love the eliminated need to compile and import classes (manually). The auto-fix/hint feature makes it tremendously easier to keep track of our errors and manage the entire project.
Adios notepad,

Source Code:




import static org.junit.Assert.assertEquals;
import org.junit.Test;

/*
*
* FizzBuzzTest - JUnit Test Case, that tests the FizzBuzz.getValue
* function to verify the string conversion is returning the correct
* value. See FizzBuzz class for appropriate conversion.
*
* @author John Ly and ICS 413 class
*/
public class FizzBuzzTest {

@Test
public void testFizzBuzz(){
assertEquals("Testing 1", "1", FizzBuzz.getValue(1));
assertEquals("Testing 3", "Fizz", FizzBuzz.getValue(3));
assertEquals("Testing 5", "Buzz", FizzBuzz.getValue(5));
assertEquals("Testing 15", "FizzBuzz", FizzBuzz.getValue(15));
assertEquals("Testing 98", "98", FizzBuzz.getValue(98));
assertEquals("Testing 99", "Fizz", FizzBuzz.getValue(99));
assertEquals("Testing 100", "Buzz", FizzBuzz.getValue(100));
}
}

==========================================

public class FizzBuzz {

/**
* @getValue -- Returns string with the number's value unless...
* For numbers that are multiples of 3, it will return "Fizz" instead.
* For numbers that are multiples of 5, it will return "Buzz" instead.
* For those that satisfy both, it will print "FizzBuzz".
* e.g. 15 is divisible by 3 AND 5 ==> "FizzBuzz"
*/

public static String getValue(int num){
if(num % 3 == 0 && num % 5 == 0){
return "FizzBuzz";
}
else if(num % 3 == 0){
return "Fizz";
}
else if(num % 5 == 0){
return "Buzz";
}
else {
return String.valueOf(num);
}
}


/*
* main -- Prints the output string returned by getValue
* for the values 1 to 100.
*/

public static void main(String[] args) {
for(int i = 1; i <= 100; i++){
System.out.println(getValue(i));
}
}
}