Tuesday, September 25, 2007

WebSpider Improvement

Thanks to the time extension, I have time to review my code again. It looked fine to me when I completed it as I was probably too excited that I can finally go to bed in the end. When I look at my code again, I find that some of the methods are too long that it is complicated to read. Therefore, I improved my codes by creating other methods and declared some variables as global. I also added more comments. This way, it is easier to see how my program works. Other than that, formatting errors such as use of tabs are also corrected. Please find my refined code here.

I have tried to work on the extra credit portion, but after playing around with the codes, throwing more exceptions and doing some research on the web. I still have no idea how to make it work and so I decided to drop it.

This is the most challenging assignment by far. It took me a lot of time and efforts but I am glad that I have learned quite a lot from it.

Monday, September 24, 2007

11. WebSpider

All tasks are completed while the extra credit section is not attempted. My code can be found here.

This turns out to be a more difficult task than I thought. First of all, there was the problem with JUnit. I didn't realize that the build.xml is incomplete and I wasted a lot of time on trying out different solution. It took me a long while until I finally find out what is wrong. This was frustrating but it gave me the opportunity to learn JUnit and Ant better.

Secondly, there is the httpunit. I was confused with all the different classes and functions like WebRequest and WebResponse. I always end up using the wrong one or having to do a lot of conversion between different types before I can get what I wanted. Moreover, the program always run into different kind of errors when trying to opening the URLs. I have to solve these problems by throwing a lot of exceptions.

Thirdly, there were no sample output and I didn’t know if the result I got is correct. This prohibited me from improving and correcting the program as I couldn’t tell how is my program doing. If I have more time, I would have build up a sample test page so that I can test my program on it.

Fourthly, I have nevery used logging in Java but it was okay as I found some useful examples on the web.

All in all, this is a challenging assignment. Through this assignment, I have explored Emma, JUnit, Ant, HttpUnit and Eclipse in greater detail. I wish I have started on this assignment earlier on so that I would have time to attempt the extra credit portion.

Monday, September 17, 2007

Stack and QA tools

Code: click to download

All five tasks were completed successfully.

Problems:
I went into several problems in completing this assignment and the following two are the major ones.

1. Eclipse
Somehow, Eclipse fails to recognize my class files and keeps giving me errors saying that the classes Stack and ClearStack are undefined. It gives me the errors now and then even when I haven't made any changes to the code. After some frustrating moments of trying out different possible solutions, nothing worked until I tried renaming the package, thanks to the advice of Mike and Chaofien. It worked, no changes were made to the code and Eclipse can recognize the Stack classes again. However, minutes later, the same thing happens and again, the problem is solved by renaming the package. In the end, I end up renaming the packages whenever the problem came up. It was an unsophisticated solution but that was the only way I could solve the problem. Does anyone have a similar problem with Eclipse? I wonder if Eclipse is having a problem with compiling the project?

2. JavaNCSS.Xml
I have never worked with XML before and so completing the task was like learning a new language to me. I was lost in the beginning but by reviewing the other build.xml files, I was able to pick up on the format and syntax. Also, thanks to the discussions on Google group, some of the problems I went into were also solved.

Ant and other QA tools:
This is the first time I use Ant and I found it very handy. At first, it was very confusing as I was not familiar with the QA tools yet. So I just blindly followed the instructions on the assignment page and typed in the command lines without knowing exactly what each one is doing. It was only until I worked on task 2 and 3 that I learned more about PMD and Findbugs. PMD and Findbugs are both very useful debugging tools. They give a concise report on what and where the error is and provides suggestions to correct the problems. They are absolutely useful for debugging programs, especially for large projects where it would be time consuming and tedious to find out those minor errors.

On the whole, I like Ant. It was a surprisingly useful and powerful build tool. It was also flexible in the way that it can incorporate so many different QA tools. Moreover, this would be especially useful in large projects where there would be so many classes and methods that we would be easy to lost track of.

SCLC vs JavaNCSS:
SCLC gives a count of comment, non-comment, blank and total lines on a variety of languages whereas JavaNCSS also give information about the size of a project but is only limited to Java. Since this class would be mainly dealing with Java, I would prefer JavaNCSS over SCLC as it could give more specific information such as a count on JavaDoc.

This is by far the most demanding assignment I had so far. For we have to install and learn to use several QA tools and to write up a xml file for the first time. There were a lot to learn. However, this is also the most useful assignment as it familiarizes me with these essential debugging tools. I agree it would be better to learn them all in one time rather than one by one. This way, we can get start using them on our future assignments right on and polish our skills.

Wednesday, September 5, 2007

CodeRuler Redux

After reading through my classmates’ codes, I found a few interesting and useful strategies and tried them on my codes. But I don’t see any significant improvement on the results, so I switched back to focusing on improving the strategies on Marcius and mine original code instead.

The major changes are firstly, instead of having two groups that attack the castle and knights separately. I added a third, smaller group that attacks only the peasants. That is because killing a peasant is way easier than killing a knight. To win code-ruler, we don’t necessary have to capture all castles but to acquire the highest score. Since killing a peasant is easier with a score similar to that of killing a knight, it is rewarding to put in some labors into hunting after the peasants.

Also, my peasants are quite good at claiming lands and I see that I don’t need too many of them. Therefore, after a specific number of peasants, the castles would just concentrate on producing knights to attack others. Besides, this would be good for scoring point as each knight counts twice the point as the peasants at the end of the game.

Lastly, thanks to the review of Jianfei and Jeffrey, I have found and corrected all the java standard violations in the code. I also kept in mind to follow the java standard when inserting and modifying code, hopefully, this program will not contain any violations.

The revised source code can be found here.

Knowing that there is the “Big Match” in class tomorrow, I tested my code against 4 instead of just 1 sample ruler to see how it did. I did 4 test runs and it wins three of the matches. I hope that was not just a coincidence and that it will continue to do well in the match tomorrow.