Tuesday, September 30, 2008

Stack Overflow Review

I recently took a look at http://stackoverflow.com/ which is a site that computer programmers can go to ask for help. I have some thoughts on the site. I thought the reputation and badge system was a very clever way of getting more people to respond to questions and to get good answers out of people. It's a good thing that there's a way to vote on whether the answers are good or bad. The content is provided by the users and there's a system in place to control the chaos of the masses. As for how well the site provides answers, I just stumbled onto this relevant question from the site. In it is a discussion on the quality of the answers. It appears that providing a detailed question will increase the likelihood of having a good answer. The user was annoyed by Google responses he recieved for some of his questions. Seems like the best way to avoid that is to also add to your question what you have tried that didn't work.

In terms of structure this site reminds me of Digg.com and other similar sites. Through OpenID, I used my Blogger website as a login to the site. I'm curious about how it can ensure that I'm the person who I say I am. It would be nice if the questions were placed in categories like C, C++, and Java to give it more of a structure than just relying on tags. It's nice though that the questions can be categorized by newest, hottest, votes , active, unanswered.

Wednesday, September 24, 2008

Using Ant

Introduction

The focus of this assignment was to use QA tools to debug some sample code. For the assignment I used Ant along with Checkstyle, PMD, FindBugs, and JUnit.

Installation

First of all, I downloaded Ant, Findbugs, Checkstyle, JUnit, and PMD along with stack-6.0.911.zip. I unzipped all the files to a single directory. One of the biggest obstacles that I encountered was just installing the tools that I needed. I often found myself googling for instructions. Once I got the first few tools installed the rest of them were easy cause they followed similar steps. Much of it had to do with setting up environmental variables.

QA Testing

Afterwards I ran through the gamut of tools to test that if they all worked. The commands that I used were:
  • ant clean compile
  • ant -f checkstyle.build.xml
  • ant -f dist.build.xml
  • ant -f findbugs.build.xml
  • ant -f javadoc.build.xml
  • ant -f junit.build.xml
  • ant -f pmd.build.xml
Once those ran correctly I opened up Eclipse and started on the process of debugging the Stack project. Fixing the bugs that Checkstyle found were the easiest cause it gave suggestions on what should be changed. Junit found issues relating to how a stack returned the top element. Instead of returning the top element of a stack, the program was returning the bottom element. FindBugs told me to use Integer.valueOf(int) instead of new Integer(int) which I never knew until know that it was an issue. There was a problem with the testIllegalPop() so I removed the try/catch block and added @Test(expected = EmptyStackException.class). PMD told me to add the final keyword to certain variables and I also had to change a few ArrayList to an interface List.

Conclusion

At first I was fustrated at getting all these tools up and running but now after using them I realized that these things will make my life much easier. I wouldn't be surprised if one day I would abhor the thought of not being able to use them in my programming.

Here is a distribution of the project: stack-johnzhou-6.0.924.zip

Wednesday, September 10, 2008

CodeRuler

www2.hawaii.edu/~johnzhou/ICS413/john.km.zhou.rar

Thursday, August 28, 2008

FizzBuzz

The program for FizzBuzz required that all of the numbers from 1 to 100 be printed out, except when the number was divisible by 3 it should print Fizz, when the number was divisible by 5 it should print Buzz, and when the number was divisible by 3 and 5 it should print FizzBuzz. It took me about 5 mins to get the correct output since the assignment felt "timed" and another 20 mins just messing around in Eclipse, resulting in the following code:

Source Code


public class FizzBuzz {
public static void main (String [] Args){
for(int i = 1; i<=100; i++){
getValue(i);
}
}
public static void getValue(int i){
if((i%3 == 0)&&(i%5 == 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);
}
}
}

Issues

Didn't have much difficulty with Eclipse since I've been using it for a while. It was probably made easier to accomplish since I witnessed it done in class. I first started working on the main and the "for" control statement, then moved on to make the method "getValue". The first time I did this in class I didn't read the instructions entirely so I was making the "FizzBuzz" conditional statement last and had to redo my if-else statement chain. This time I made sure I started that first. Another issue came up where Eclipse wanted me to make the "getValue" method static, probably because I was calling it within the same class. The last problem was in the formatting where the output wasn't line by line so I just added newline statements to the print.

Conclusion

It was nice to know that I could pass this screening test for decent programmers. I found that I should read the entire problem before jumping headlong into programming. From reading the other blogs, I found that I should have probably used a print line in the for loop and passed Strings to it from the getValue method.