Monday, December 10, 2007


In this entry I will talk about how the following tools and techniques support one or more of the Three Prime Directives.

1. Interactive Development Environments (Eclipse, VisualStudio, etc.)
It support PD 3 by providing great help in developing. Good IDE can provide much more than a text editor. It can not only compile and debug programs, but also give out useful analysis such as package tree, class outline and documentation of classes and methods. Some of them can even provide useful auto edit function, such as refactor in Eclipse.

2. Coding Standards and Coding Standards Compliance Tools (Checkstyle, etc.)
It supports PD 3 by greatly increasing the codes' readability, thus helps developer to understand the program better. When all variables are given with meaningful name, developers will be able to read the code just as a article.

3. Build Systems (Ant, Make, etc.)
It supports PD 2 & 3. As a automatic mechanism, it hides many specified detail in building process that user could just type some simple commands to build up the whole system. To the developer, facilitate the building process is also helpful. And as build systems are IDE-dependent, it enable developer to choose whatever he like to develop.

4. Automated Quality Assurance Tools (PMD and FindBugs, etc.)
It support PD 3 by ensuring a better code quality. These tools could help clean many implicit bugs and ensure some more reasonable coding style, which may be more close to programmers' common sense. A system with fewer bugs are surely more friendly to developers.

5. Black and White Box Testing
Testing supports PD 1. It guarantees the correctness of the system so that it can run as expected and accomplishes the tasks successfully.

6. Automated Testing Tools (JUnit, HttpUnit, etc.)
This supports PD 3 by providing a automatic checking mechanism to make sure what the develop modified is proper. If the unit tests fails after some hacking, developer will immediately acknowledge that some hacking mush be wrong and therefore bugs can be fixed cheaper.

7. Configuration Management (CVS, SVN, etc.)
It supports PD 2 & 3. Users can easily check out the system from a repository and, with a well developed build system, build the system for use. Developer gain more benefit from CM system that it facilitates collaborating development. It tracks down the system's configuration all through its life-time so that errors introduced in some versions are more easier to found and fix or recover.

8. Issue Driven Project Management
It supports PD 3 by providing useful guide line for new developers that what is deficient right now in the system so that they will have better idea of what to do to contribute to the development.

9. Use Cases
It supports PD 1. Using use cases, developers can better understand what users expect and therefore build the system that way. Developers can have better communication with users with use cases and let users know what the system will be and properly do some changing, even before the system is built.

10. Software Review
It supports all 3 PDs. It provide another way to test all the 3 prime directives. Developers could get more feedback as an external user or developer so that they can do a better job to perfect the system.

11. Agile Methods (XP, Scrum, etc.)
It supports all 3 PDs. With better communication with customers, developers are able to ensure what they building can really satisfy users need. New developers will find it helpful to attend daily meeting to gain some general idea of development process. And simplicity also make it easier to understand and maintain.

12. Open Source Licenses (GPL, CPL, etc.)
It does not support prime directives directly. But it may have some contribution to PD 3 because new developer may feel easier to continue a software with proper license that he will not need to worry about legal responsibility in copyright to the original developer.

13. Online Hosting Services (Google Project Hosting, SourceForge, etc.)
It supports PD 3. Online Hosting Services provide developers a great place to share developing source, including codes and other materials. With CM tools, developers can easily check out others work and submit his to keep codes up to date. That much accelerate the development process.

Thursday, November 15, 2007


Group viewed: MyIsern-Purple

Installation Review:
The installation is not as smooth as previous projects. First failure is from the String.isEmpty() which is not supported in Java 5. I will have to keep fighting with this problem untill Java 6 for Macintonsh released. Then when I importing it into Eclipse, the buildpath fails. However, it is not difficult to fix and get the isEmpty thing fixed for me too.
Then PMD and Checkstyle run successfully. But the JUnit test fail. The first problem for its failure is because their working directory's name is different from project distribution directory's, which included the "purple", and the project then is deployed with the name myisernweb-purple. Therefore, the test get a 404 when accessing the page. After fixing this, 4 tests still fail, HTTP 500 are reported. In tomcat there are 2 exceptions pop out when tests fail. These may be some real bugs, but I did not see into the code to find out what is happening.
The installation clear enough for me to get the software run.

Code Convention Review:
Some unused private variables and methods are reported in Eclipse, which might be historical remaining.
Some class share a same java doc, which is probably copy-pasted.
The most important violation is that the class Id implements a raw type Comparable, which is highly not recommended in Java 5. The right interface should be Comparable. and then the compareTo method will take a String as parameter rather than an Object.

Test Case Review:
First I notice that the EMMA's setting is not correct that takes jaxb class into coverage comptation.
The test cases are far from enough. As reported in EMMA, most methods in ActionBean are not tested, and only 66% methods in model are tested. I am not sure if the coverage is effected by the failures in JUnit test.
One bug I meet is when click save with name field empty, the system will end up to an exception.

User Interface Review:
The user interface is pretty good! Not only the functionality, but the appearance. In researchers page, there are picture in front of each person. When adding/editing new researcher, I can easily choose an existed organization from a drop down list, or create a new one. In collaboration editing page, years and organizations can be selected from multi-select field.
However, one important function is missed: delete objects. Objects cannot be remove once being added.
The affiliate researchers field is missed in organization editing window. Maybe authors thought that is should be determine by researchers' organization. But there are no view page available, so I cannot see an organization's affiliate researchers by any means.
Though using multi-select field to deal with multi-value field is really a good idea, it will become hard for user when selections become numerous. When using last assignment's data as input, there will be tens of organizations in collaboration's selecting window. However, I don't have much idea of how to do it good, and this approach is actually the best I have seen so far. But I think it is necessary to figure out some better way to do it.

MyIsern-Purple's 1.3.1114 distribution is overall amazing, in consideration of such a short develop time for it. I do see many things useful for my project in it. I am more convinced that user interface is significantly important. This application's functionality is better than mine. But when looking at its nice pages, I do feel that my application is not comparable to this one.

Saturday, November 3, 2007


1. Explain in your own words the meaning of the web "request-response cycle".
A: User request a page by clicking or some other means. The brower prepare the request and send it to the server, then receive the response from server and show in to the user.

2. Explain how servlets facilitate processing of the request-response cycle.
A: Servlets are able to generate page dynamically, so that the server can return much more different pages accordingly, without storing them beforehand.

3. How do you login to the Tomcat Manager?
A: I access my Tomcat page from http://localhost:8080/, then click the Tomcat Manager on the left to login, with username and password.

4. What is the Tomcat Manager used for in the StackStripes application?
A: Through Tomcat Manager, we are able to deploy our StackStripes without stopping the server.

5. What is the directory and file layout of an installed web application like StackStripes? (This is NOT the same as the directory and file layout of the StackStripes distribution!)
A: the web applications are installed in $CATALINA_HOME/webapps. Inside each application's directory, there is a directory called WEB-INF, where stored the code of the application.

6. How do you build a war directory structure in Ant? Where is this accomplished in the StackStripes application?
A: We build it using war task in an Ant target. It is done in build.xml, in the target "war".

7. How do you install a war directory in a running Tomcat server? What information does the Ant task need to accomplish this?
A: By getting this page: http://localhost:8080/manager/deploy, with argument path and war.
Ant need the host's address, the system name to generate the path, and the war file's location.

8. What is the "Model2" architecture? What are its advantages?
A: MVC contains 3 part: Model, which run web application, access database and generate the response page; View: whatever you see in your browser; Control: connector between Model and View, process user's request from view, interact with Model, and return the page to be shown next.
Its advantage is separated program logic from user view, so that it is much easier to modify and maintain the web application.

9. What are JSP pages? How are they related to servlets?
A: JSP is a page that contain static text data such as HTML, and dynamic content such as scriptlets or stripes elements. It can generate the proper page according to user's interaction. JSP will be compiled into servlet when first time it is requested, and recompile later when needed.

10. Why is there a delay when retrieving a JSP page for the first time? Where is the Java code for that page stored?
A: Because JSP will be compile into servlet for the first time retrieving. The Java code is stored in server.

11. What are JSTL tags? Why are they useful? What is an example JSTL tag from the StackStripes system?
A: JSTL tags are a kind of xml tag in HTML to implement some kinds of functionalities. They are useful because of their simplicity, which enables people other than Java programmers to modify the code. Example JSTL tags in StackStripes system are:

< c:foreach var="element" items="${actionBean.stackIterator}">

12. What are Stripes tags? Why are they useful? What is an example Stripes tag from the StackStripes system?
A: Stripes tags are tags that present functional framework that defined by Stripes. With Stripes tags, we are able to separate the Java control codes from JSP pages. All Java codes can be put in Java classes and called by Stripes tags.
Example Stripes tags in StackStripes system include:

< stripes:form id="PushForm" action="/Stack.action">
< stripes:select size="1" name="numToPush">
< stripes:option value="1">1
< stripes:submit value="push" name="push">

13. What is HttpUnit? How is it different from JUnit? Why is it useful? What is an example use of HttpUnit from the StackStripes system?
A: HttpUnit is a testing framework that emulates behavior of browser to test the function of web sites or web applications. Unlike JUnit which is a unit testing framework for all java programs, HttpUnit is focus in testing web applications. It makes it possible to verify web applications or web sites by automated testing.
An example in StackStripes system is :

WebConversation conversation = new WebConversation();
String Url = testHost + "stackstripes";
WebResponse response = conversation.getResponse(Url);
assertEquals("Checking index.jsp retrieval", pageTitle, response.getTitle());

which check if the page is retrieved correctly.

14. What needed to be changed in order to implement the Double It button? What didn't need to be changed? What did you learn about the MVC design pattern from this exercise?
A: I need to add a stripes:form for the Double It button, and all other things remain unchanged. MVC is very facilitated to use, as simple as to add a method in a class.

15. What are the equivalence classes that need to be tested for the Double It button?
A: empty stack and stack with some elements.

16. Provide two screen images of your new StackStripes application with the Double It button, one showing the page before and one showing the page after hitting the "Double It" button.
A: before:


17. What is the singleton design pattern? What is an example of its use in StackStripes? Why is it needed?
A: singleton design pattern is a design pattern that ensure there is only one object of the class in runtime. In StackStripes, a static instance is defined, And the construction method is private so that users can not call it to create a new instance. Also, there is a getInstance method serve as the function as constructor, which always return this static singleton instance.
We use it because we need to ensure that users are interacting with the same instance wherever the open the page.

18. Some of the StackStripes tests exercise code on the "server side", while others exercise code on the "client" side. Which test classes exercise code on the "server", and which exercise code on the "client"? How does Emma deal with this to create appropriate coverage data?
A: Tests in TestStackModel exercise codes on the "client" side, and tests in TestStackActionBean exercise codes on the "server side". Emma track the running code in server side and put those data in However, emma has to stop the server to make that file finalized onto disk so that it can be read to create appropriate coverage data.

19. Running 'ant -f' results in the following target invocations: tomcat.check, tomcat.undeploy, compile, war, tomcat.deploy, junit.tool,, junit. Explain what each of these targets do.
A: First, tomcat.check target checks if tomcat is running and can be access properly. Then, tomcat.undeploy target undeploys the existed web application in the server. After that, compile target compiles the java codes and war target packs all web files into a war package. Then tomcat.deploy target is called to unwar the war package and deploy the web application onto server. After deploying, junit target awoke junit.tool and targets to run the unit tests in the web application and generate an HTML report of the JUnit tests.


Source code:

Thanks to the reading pages and the lectures in class, I did not encounter much problems in this assignment. The only one problem I faced is emma failed at the beginning. This problem is discussed in our google group. I finally found out that it is because the default directory where the will be save is relative to the directory where you launch the tomcat. So there seems no universal environment independent approach to this problem. Even if we change the output directory to an absolute path, it will still need to do different setting in different environment, at least in different OS such as Mac and Windows. As I am used to launch my tomcat from HOME directory, I modified the to look for in HOME directory.

EMMA coverage:
[concat] Emma Coverage summary
[concat] class: 100% (2/2)
[concat] method: 100% (18/18)
[concat] block: 98% (141/144)
[concat] line: 96% (46/48)

The only 2 lines that are not tested is the statement that catch EmptyStackException in doubleIt when calling in action bean. However, these 2 lines will never been reach because the the empty stack is checked in doubleIt method in stackModel. But I still what to keep these 2 lines of code in case the program will break down in the future, and keep it that way rather than just throws it because "nothing should go wrong in the view".

Monday, October 22, 2007


Project home: myisern-1-ivory
Use cases in Wiki

Use case is a very useful way to clear up my mine of what is need to be done in the system developing. Writing use case is to look into the system in terms of actor. Looking as user give me better comprehension of the system. The most important part of writing use case specification is to make it simple, as concise as possible.


Project page:

All tasks have been completed.

This assignment is not a technical difficult one. All it needs is to read command line input in runtime and put it into data. There are many field in each of 3 objects and adding codes are very similar, but not similar enough to use some methods to group them all. Though we can divide our job by different input part, we cannot divide it into different file. So this comes the first time we try hacking into the same file in the same time, but with different part. Though we try our best to not modify any codes in others part, we still get a commit error. At last, I have to put my partner's hacking by copy and paste into my code to make it a whole.

After built the first runnable version, we got lots of bugs and fixed them. One of the most critical bug is cause by Java's parameter passing mechanism. When doing input in multi value fields, it comes out to input a List of String, so we use a method to deal with all these fields. At first, we send the original one as parameter, and try modify it directly inside the method, but the result came out to be incorrect. Then we found out that is because we use the expression like currentList = inputList. Later we change it to return the result List of String and it finally work well. This is because Java pass the parameter by pass the pointers of the object by value, not the object itself. So we doing currentList = inputList, it actually change the value of the pointer passed from parameter, but not the original object. Now I know that if we need to modify the object from parameter to a new one, we need to use the method within the instance, not the "=".

During the next milestone, we will probably add more help and make input more convenient.

Tuesday, October 16, 2007


Project reviewed: myisern-1-green


At the first try, I was astonished that the code I downloaded cannot even compile. Then I found out that is was because I am using Java 1.5 while the code use the java.lang.String.isEmpty() method which is added in Java 1.6. Java is evil, and Macintosh with java 5 is evil too.
At the review perspective, my review cannot going any further now. Meanwhile, I hacked into the code and fixed it so that it can work with Java 5 and continue my review.

Code format and conventions
Document all members
Use meaningful name

Test case
Whitebox perspective:
The test case did a very good coverage as much as 96%. Only some lines of printing out error message are not reached. However, the results are not checked. Tester can only look into the output to see if thing goes right.

Blackbox perspective:
There is no blackbox test. All test, except those come from example, are to call the main method with different arguments. There are actually many methods that return meaningful object, which should be test with quality.

I notice that the system did not maintain the Unique ID to be unique across the entire system. Only duplicate within Collaborations, Organizations or Researchers will be prevented, but not between them, such as a researcher and an organization with same name.

What I feel is that things can go wrong in any possible way. I have never image the Mac with Java 1.5 will cause me trouble until I faced it today. However, try to avoid use the very new things will be a good idea unless it is necessary. In case of check empty String, String.length() = 0 will also finish the work. That will avoid some more problems.

Monday, October 15, 2007


Project page:

All tasks have been completed.

The main difficulty of about this assignment is to deal with various commands. We did this by create a class contains enum fields and switch these fields. It works good, but not good enough. I think in our next Milestone, which need more commands, I will change it to instance factory model, producing sub class of the parser to separate different enums and situations.

We are using the issue driven method in this assignment. The first thing we did is to write issues, and then we pick issues to deal with. On Thursday, we met in library and work together in the afternoon. During that time, we finish building the whole main structure of this assignment. Working together like that is really great, and is of efficiency.

Monday, October 8, 2007


Code Author: MyISERN-1-Blue: Marcius Bagwan, Sonwright M. Gomez and John Hauge
Project Page:

Installation is smooth. All ant check pass. But when I import the project into Eclipse, there is a warning of unused import: import static org.junit.Assert.assertTrue; in

Code format and Convention:
There are a few violations:
Use meaningful name
Document all members
One sentence summary

Test Case:
As all 4 methods, which are new from example, return void, there is nothing much to assert in test.
In white box perspective, the test coverage is 100% according to EMMA, so it is well done.
In black box perspective, there are only a few conditional statements and all of them all satisfied at least once.
However, I found some problems:
1. Two format mistake when printing organizations. First, it prints the country as "CounterUSA", which should be "Countery: USA", I think. Second, name is printed like "Name:University of Hawaii", where I think a space is missing because every other places in the table, ":" always follow by a space.
2. Though he program has a good command-line arguments and also help message, the program exit without any word when using error argument. Help message should come out in this situation.
3. If the xml file contain an empty element like , or missing a element which would contain other elements, the program will end with NullPointerException. However, these kind of xml files will fail when running Therefore, the mistake of the program will be running without validate the XML files first.

I am surprise that though code format and convention has been used and emphasized for so long, there are still violations in our codes. It seems to be easy to follow exactly the rules required. But actually, it isn't. Lots of practice is needed.
About test, though methods return void is evil and hard to test with assertion, we still ought to do it seriously, at least to guarantee that the output looks right, such as correct message with proper format.
Null object are evil and can usually break down a program. Most of the reasons when it happens in actual application is because of illegal input, for example, miss some essential parts or mis-structure format. So we really need to make sure to validate input before processing it.

Sunday, October 7, 2007


Source and Distribution can be found at

Here is the first task of collaboration. My group have two people, me and Ben Karsin.
In Thursday, the day after last class, we meet as required in library. But, as none of us have actually initiate coding, we think the meeting is useless. Then we change our plan to keep in touch online, mostly by email.

In Friday and Saturday, we did not meet each other. Then problem came out. Our emails are replied with delay as long as 20 hours. Then our whole schedule has been postponed. I then realize how important the daily meeting is. However, as Sunday comes, we don't want to meet in school again. So we decided to keep contact online by Skype. But it works! We can communicate as well as face to face. Therefore, we complete most of our code in an afternoon.

In my opinion, daily meeting is significant, but real-time communication via internet is important too, or even better. Because meeting is only a short time in a fixed time, while communication can be all the time. However, it maybe just the case when only 2 people in a group, when members become more, meeting should be more efficient, especially in initial design.

In the first day we meet, we don't settle down an overall design. When I start to write codes, I have to worry about what my partner will write, will our code be able to combine? Though change may be applied latter, we do need to get a better design at the beginning. As least define some interfaces, which will guarantee usability in certain way.
The result of our collaboration is that I write codes and Ben test it.

Overall, this is a very helpful experience of group development. It is interesting to develop with others.


The Google Hosting Project I created :

In this assignment, our goal is to install SVN, try it and create a new Google Hosting Project.

In my practice, everything goes well. I finish the first 2 tasks without problems.
When creating Google Hosting Project, I face a small problem that when modified codes, no log is sent to svn group. My problem is cause by adding wrong member in svn group. At first I thought that the "googlecode" in should be replace by the project's name. The right way is to add "" as a member.

What I learn, or say realize is that the experience in previous assignment is really helpful. Now I can install tools, modify environment variables and test code smoothly.

Sunday, September 30, 2007

Review of Webspider-chiaofen-1.0.926

Review package: webspider-chiaofen-1.0.926, Package Author: ChiaFen Zielinski
1. Installation Review:
Installation is smooth. I did not encounter any problem when installing and trying to use this package.
Junit, PMD, Checkstyle, Findbugs are all passed with no errors or warnings.
Emma Coverage summary
class: 100% (1/1)
method: 100% (9/9)block: 93% (726/784)
line: 92% (140.1/152)
This is a good coverage.
However, there is a small problem that when running java -jar webspider-chiaofen.jar-totallinks 100, It printed out plenty of empty lines. It may because of the logging scheme, which was implemented with println().

2. Code format and conventions review

WebSpiderExample.java25-31EJS-39Document all members.
WebSpiderExample.java294EJS-32Document is unrelative to the method, which is copy-paste from another method.
WebSpiderExample.java241EJS-33Keep comments and code in sync.
WebSpiderExample.java299EJS-9Use meaningful names.

3. Test case review
  • Black box perspective.
traversePages(String urlLink, int numLink), findMostPopularPage() and findTotalPages(), these 3 method actually are not tested. The test method only call the main method once that will use these method and assert a meaningless assertion.

getNumLinks(), this method is tested properly.

isNum(String s), only method is called. Result is not verified properly.

logList (String urlLink, int numLink, String logging), same as above. But this is a method returns void, verify result may be difficult. However, I think do some digging into the data of the test object is able to verify as least a bit of the result, while author verify none.

  • White box perspective.
I have to say that, the test case is terrible. It actually does no meaningful test. What it does is only to run the methods and see if there is any exception or error comes out. Nearly no result is tested. 5 of the 8 test method use assertEquals ("test", testUrl, testWebSpider.startUrl) to verify the result, which is meaningless in most of the test. The test pass even when I add some bug code in the class code. I think the only propose of this test case is to pass EMMA with a high coverage.

  • Break da buggah.
When I run the program with arguments of -totallinks, it ends with Array Index: java.lang.ArrayIndexOutOfBoundsException: 2.
When using -totallinks 99999999999999999, it throw out a java.lang.NumberFormatException and break down.

4. Summary and Lessons Learned
We should really do out test right, use it to test our code, not to pass the QA tools.
My code does not do well when I test with the arguments above which cause problem. I didn't think of these things either. I only catch them and give out a warning. I think I can do it better by adding more useful statement that will help user use it right.

Wednesday, September 26, 2007

About the extension assignment of WebSpider

In fact, I did not do much about it. However, I found a page that mention something similar to the matter. Here is the link: I have download and tried his code, but not act well enough. The retrieving seems to be unstable. Sometime it can retrieve some javascript pages but some time gives out error Invalid URL encoding or Unexpected end of ZLIB input stream. I don't know why, but this may have something to do with the search algorithm that I store the only the link to visit later, but not the WebConersation object. But I did not take time to modify my code for a further test.
I think hack into httpunit is the only way. I did find some crawler, but most of them are implementation like our webSpider, which also base on httpunit, so of course do not fully support javascript.
I read in httpunit's website that full support for javascript is one of their aim now. Maybe next version will fixed this problem. :)

Tuesday, September 25, 2007

WebSpider Extension
Most part of what I did is about the testing.
First, I rewrote my test class and separate tests that one test method test one of the target's method. But there is one exception. I will talk about it later.
Second, I modified the method that return void. They are retrivePage(String) and getPages(int).
Both of them are modified to return an int value. The return of retrivePage(String) is the number of links found on this link. The return of getPages(int) is the number of pages that actually retrieved. After that, I found it easier to test them, but also better to know them that I did not know how much pages were actually retrieved before.
When I check for the pmd, it tell me I have to add a assert in testWebSpider() where I test the main method by only call it. In order to past PMD, I added a test of another method with a assert. So this is the only test method that test 2 methods.
I amitted that to do this in order to past PMD test is not a good way. But in the view of PMD, I think the proper way is remove that whole test method because it actually has nothing to assert. However, I would like to keep the test. I think keeping the test is more useful than satisfying PMD.

Monday, September 24, 2007



Task 1~3 are accomplished.

Encountered troubles:

1. To saved URL from WebLink. The trouble is becase the WebLink object's getURLString method sometimes returns a incomplete URL. I have tried to fix it manually, but did not make it. Then I tried to store the WebLink object instead, but it still does seem to work. Finally I was told that webLink.getRequest().getURL() will return what I was looking for, so I used it.

2. Deal with exceptions while accessing pages. At first I tried to modify my code so that it can deal with more and more exception. But soon I found that the exception type various as much as pages on Internet and some of them are cause from javascript which httpunit support poorly. So, alternatively, I catch and log them instead of solve them. Also, I turn off httpunit's exception throwing when counter a javascript page.

3. To log. After reading in it, I found that the logging package is really convenient. I can log different message in different level that can be easily controlled and filtered. I only need to change setting in initializing. But then I encounter a problem when trying to print out the logs to Console. I tried nearly all classes in the package when found out that a new handler must be create in order to do what I want.

In testing, I found out that command arguments in main() method can be transfer by a String array. But as the main have not a return, I don't know how to assert the running result. The test just prove the code can be execute, but not guarantee the rightness. However, the test can cover over 90% method-lines. What are not covered are the exception catching expression. But if I change the argument to make it process a job of larger scale, it is sure that these line will be covered. I don't know whether testing like this is a right way. But it seems to be the only way to test a method without a return.

In this task, I really feel that the QAs tools are not additional jobs, but facilities. Used the xml files build in previous assignment, I nearly don't need to look into it anymore. Just use it to examine my code! That feels great. I think I will be greatly benefited from them in my future work.

Sunday, September 16, 2007

Stack - Experience of Ant & QAs

Stack-shaoxuan-5.0.916 is released. Distribution package can be download from

The goal of this assignment is to learn Ant build system and Open source Java automated quality assurance tools (FindBugs, Checkstyle, PMD, etc). It is an interesting experience.

Task and Problems:
There are five tasks in the assignment. All of them has been completed. I have encountered some problems when installing QA tools and creating JavaNCSS project(Task 1 & 4). The other 3 tasks are easy.
problems in these tasks are mainly because I got my Macbook this week and it is the first time I use the Mac OS. I took a long time to figure out how to set the environment variables when I was trying to install those QA tools. Then when I trying to build the JavaNCSS project, the CLASSPATH thing held me for a while again. But now, when I solved all these task, I learnt things not only about Ant and QA tools, but also Mac OS.
The most important things in these tasks is to setup environment variables for every QA tools. It is significant to make then run right. In Mac, I need to run a terminal and use vi to create/modify a file named .profile in my home directory(where cd ~ will take you to). You cannot see the .profile in Finder, that is the reason why I confused. In the file I put all the definition of all the environment variables. When doing task 4, I got confused with the CLASSPATH because there is not a CLASSPATH definition when typing printenv, but the java compiler runs well. Then I know that it is because JAVA has enhanced in Mac OS and the compiler will search default directory for java classes. I can use CLASSPATH=./:{other directory} to add new destinations to CLASSPATH. But later, I found that the class required by javancss can be defined inside That is a better way and I use it.
When improving the unit tests, I think it is easy that just add lines to test every methods and use the try/catch expressions to test the exceptions.

Impression of Ant and QA tools:
Ant is really a great tool that facilitate the automatic building procedure. Though its command structure is not so easy to learn from the beginning, its power enable us to build however we want to.

Difference between SCLC and JavaNCSS:
Though these two tools are both use to count lines in code files, SCLC count also blank line, which I think is useless, while JavaNCSS counts CCN(Cyclomatic Complexity Number) and average of NCSS, CCN and Javadoc per project/package/class/method, which make sense in knowing about the complex of your code. Therefore, JavaNCSS is what I prefer.

Saturday, September 1, 2007

CodeRuler Revision

New version of source code:

After studying the score rules and testing codes from UCSD Spring 2004 Programming Contest. I made a lot of changes in my strategy.

Strategy of Knight:
By testing the codes of XXX_420_XXX, the second place of UCSD Spring 2004 Programming Contest, I surprisingly discover how excellent a simple brainless strategy can perform. Its idea is very simple: capture the nearest castle. It doesn't even group up knights when attack or annihilate enemy units when captured all castles. It just let every knight attack the castle that is nearest from it and let them stand still while all castles are captured. However, in most of the test matches, it does succeed to capture all castles! No one can ever beat it in castle capturing, though its stupid stand still method makes it some trouble because it doesn't notice when enemy knights are kill its peasants, as long as they don't capture castle.
Therefore, I decide to switch my strategy to a similar one: capture the nearest castle and annihilate enemy units when all castles are captured. That works pretty good. It acts just like a blitz, and is able to take all the castle within 150 turns when fight with samples! (500 turns per match)
I think one of the reason to its success is that it naturally separates its force in groups that maximum the possibility of surviving in raids and efficiency of capturing castles. The success of such simple idea is amazing.
I have also test the code of champion of UCSD Spring 2004 Programming Contest, its AI is much better. It will score every castle depend on the distance and nearby defence and select the best one to attack. It sounds nice, but it doesn't work so well in my test. One of the reason is its knights seems hesitant when selecting target, and this makes the capture procedure much slower.
Perhaps, to be simple is just a good idea.

Strategy of producing:
By studying the score rules, I found a key of getting high score when winning the match. That is to produce knight rather than peasant when your peasants are enough. The reason is, a knight scores 2 and a peasant only scores 1 at the end of the match. And, you don't need to continue to create peasants in order to claim all land. As I tested, even 40 peasants will be enough to claim more than 4000 land. So I continue to produce knights when I have 50 peasants. It just likes a cheat! I increase my winning score by 400 by just adding such simple expressions! That makes me possible to win the highest score event in case that I lost over a half of matches, and guarantees me the champion as long as I win a half of matches.

Strategy of peasant:
Nothing special. I just extended the searching area when choosing directions to improve the efficiency of claiming land.

Friday, August 31, 2007

CodeRuler Review

I have reviewed Ben Karsin's code of CodeRuler from His AI strategy and algorithm is fantastic and his code is well written. His score system in direction decision is a very good idea. However, it seems a little bit too intelligent.
The first obvious problem is that his peasant will go up and down in a couple of fields when nearby fields are all claimed. It can be fixed simply by adding a random mechanism when all directions score the same.
The second problem is a bug that when his knight trace chased enemies' peasant to the world's angle, it will stop a block away from the target without attacking it. I don't know what's going wrong in the algorithm. This bug needs to be fixed.
The third one, which I think is most important, is a question about knight strength. In Ben Karsin's Ruler, knight runs away when its strength goes down to a degree. This strategy does protect knight from being killed, but it significant reduces the usable power of knight. Because when a knight runs for live when its strength goes below, for example, 10%, that means only 90% of a knight's power is usable. Although run-away knights can go to capture enemy knight, it makes enemies' knight able to attack anything as they wish, such as castle. In my opinion, warrior is honored to die in the battlefield bravely. So I don't agree in run-away strategy. Maybe let one or two knights go to capture enemies' peasant when strength gets low is OK, but most of the knight should fight to death.

Following is the summary of violations in the code.

Summary of violations

MyRuler.java16,29,30,*ICS-SE-Eclipse-2Code indented 3 spaces or tab, not 2 throughout.
MyRuler.java16,29,138,*EJS - 7 Lack of space between operations and parenthesis.
MyRuler.java104,106EJS - 76 Use experssion instead of block statement.
MyRuler.java114,116EJS - 5 '{' in a new line, not in the last of upper line.
MyRuler.java181,182,183EJS - 6 Lines too long.
MyRuler.java142,196,276EJS - 9 Do not use a meaningful name.
MyRuler.java74,81,90,*EJS - 37 Used C-sytle comments to explain implementation, not one-line comments
MyRuler.java250N/AThe first if statement contains a blank expression, though is not prohibited by the rules, it made me somewhat confused.
MyRuler.java224,50,54,*EJS - 7 no blank lines to seperate each member of the class

Wednesday, August 29, 2007

Code Ruler Results

Member: Shaoxuan Zhang

Source Code:

- Castle produce to maintain a certain proportion between knights and peasants.
- Peasants claim the land that isn't belongs to the rule and avoid being attacked. Otherwise, it move to a random direction.
- Knights are grouped into two, one assault team one castle capture team.
-- Castle capture team capture castle one by one, and destroy enemies' target around its way or near the castle.
-- Assault team capture castles only, do not attack any other enemy units. If no castles remain, they will wait in the center of the map for orders.

Test results:
Test 1 Test 2 Test 3
sz vs. Migrate 820:0 784:0 797:0
sz vs. Gang Up 780:60 796:78 785:42
sz vs. Split Up 773:54 844:56 749:54

Lessons learnt:
CodeRuler: I now have understand some strategy of CodeRuler. Most of them have been implemented into my Ruler. Both my peasants and knights have advantage.
Peasant: Instead of move randomly, my peasants now know to move and claim an unclaimed land first. It is significant to accelerate the speed of claimming land, and contributes to mine beating Migrate Ruler to 0 points. In most of the test, my ruler claimed as much as 4000 land which means 85% of the world! In test of more player, this number can reach 4602, which just 6 fewer than the world. I think it is strong enough. Some intelligent strategy may farther improve this one, but the improvement will not worth the expense in calculation.
Another advantage is to avoid enemies' knight. The peasant will move away from the enemy knight if it is near. This feature not only make my peasants more safe, but also waste enemies' force to pursue the peasants. Sometimes, we can see other ruler's knight running after my peasants across over the world. Though my peasant sacrifices at last, it win me lot of time to capture the ruler's defendless castle.
Knight: The idea of spliting into two teams comes from the sample Split Up ruler, and it prove to be useful. The assault team can usually find and capture a empty castle.
However, the most important idea is to sweep out the way to the target castle, especially in one on one game when both rulers' knight is moving to others. When raiding not only capture enemy unit on the way, but also near the way, it will act as defending when attacking, especially for the knight that newly created from the castle. I think this idea is the most important one to help me win.
Castle: Castle's strategy is simple, just manage the proportion between knights and peasants and stop creating knights when enemy runs few.

Java, Eclipse and Programming: Actually, I did not get much new in Eclipse, just get more used to it. For Java, this assignment is a very good exercise of writing javadoc. After I generate my javadoc files, I do consider it helpful! I think I will continue practise and use it the future.
Then I would like to talk about programming. I got two experiences: the first is to design well before writing code, the second is to write more methods to group up the functions. Both these two are fundamental indeed, but now I have fully realized them. I have writen the ruler twice. The first time I wrote it without carefully design. So my ruler cannot even beat the Gang Up Ruler. The second time I rewrote it with careful design and used more nested method calling, that prove to be very helpful when lately I want to modify my strategy.

Working with another person? I worked alone in this project, so... no experience in this aspect.

Sunday, August 26, 2007

Areca Backup -- an Open Soucre Software Experience

Areca Backup is an open source software, you can see its project in
Areca Backup is a file backup tool written in java. It supports data compression & encryption, incremental backup, file history explorer and many other features. Areca Backup also includes a transaction mechanism which guarantees your backups' integrity. --the description is copied from the link above.
Now, we come and see if this OSS satisfy the 3 Prime Directives.

Prime Directive 1. The system successfully accomplishes a useful task.
Areca Backup does do a good job in its task. It provides a very powerful and facilitative backup function. We can easily create a target of folder(s) and backup it. The archives will be save in the defined location and can be managed within the target. Also, targets can be grouped that makes us easier to manage them. When backup a second time, it will compare the existing files with the backup files, only the changes will be saved into the new archive. In recovering, we can either recover the whole folder or select some of the files to recover, that makes daily backup fast. What is more, we are able to choose in with archive we want to recover from. It is really a very helpful backup software.

Prime Directive 2. An external user can successfully install and use the system.
It installation is very easy, just need to run the install package and click next till finish.
However, the guide for new starter is deficient. There is no any guide of what to do to make the first backup archive, even in help website online. It took me several minutes to find out how to start and what a target means. But after beginning, it is easy to use. By adding a initial guide, the familiar time will be shorten from decades of minutes to couples of minutes.

Prime Directive 3. An external developer can successfully understand and enhance the system.
Though there is a source available in download, unfortunately, I did not find any develop-level documentation. I am able to create a project with the downloaded src, and the code is well organized. But it is difficult to read into it without guiding documentation. So I cannot do anything with the project. Thus, I think this Areca fails Prime Directive 3.

Areca Backup is a useful software. It can help us in daily backup procedure. But as an open source package, it is not friendly to external developers. However, considering its value in future use, the investment will prove its worth. Maybe the package will be more developer friendly with some further information from the project admin.

Tuesday, August 21, 2007


As an assignment, I just finished the FizzBuzz in Java on Eclipse. It took me 35min to do so. Since learning java for not so long time and not writing codes in java for month, I have totally forget even the basic syntax structure such as where the program begins and how to output a word. It took me most of the time to getting the memory back by searching in java's doc, but get nothing. At last, I found the answers in the "helloworld" tutorials... After that, I just spend several minutes to finish the program.
Fundamental is of most importance because you can nothing without it. Just like the beginning of my programming, I have all the idea even the codes in my brain in C++, but I don't know how to write the correct code in java. Maybe the basic elements of java & C++ are almost the same, but just almost, to program right, we need the exactly right one. Though much of basic codes can be generate by the platform automatic, it did not provide me one. Therefore, be familiar with the programming language is all the time important.

Following is the codes of my FizzBuzz:

public class FizzBuzz {
public static void main(String args[])
for (int i=1;i<=100;++i)
if (i%3==0)
{ System.out.print("Fizz"); }
{ System.out.print("Buzz"); }
if(i%3!=0 && i%5!=0)
{ System.out.print(i); }
}//end of main()

I have just read all others blog associated with FizzBuzz. I found that they all (i%15) to find out the case when we need a "FizzBuzz". But in my codes, there is not an (i%15) because the "FizzBuzz" is composed by "Fizz" and "Buzz". "Fizz" comes from (i%3) and "Buzz" comes from (i%5), so no (i%15) is needed. Meanwhile, as both (i%3) and (i%5) will be executed in any case, I cannot simply use a else to cover the remaining cases. So there comes to be an (i%3!=0 && i%5!=0) . In this FizzBuzz case, my implementation needs 4 compare statment while the other just take 3. But when the factor increase, such as FizzBuzzDozz(3,5,7), my way increase 2 compare statment every new factor while the other increase by P(n+1,2)-P(n,2)=n. That will be huge when factor become more. And, some of the item will easily be forgotten.
However, it looks like the algorithmic thing rather than the software engineering one... Anyway, just left it here :)

Monday, August 20, 2007

Frist log

The beginning of the Blog....