Welcome to my blog.

Showing posts with label Stack. Show all posts
Showing posts with label Stack. Show all posts

Sunday, November 23, 2008

My first Wicket Web Application

| 0 comments |

There are many frameworks available today for creating dynamic web applications, some of which are extremely complicated and hard to use. Wicket is one of the few, easy to use tools out there that works well with Java programming. What makes Wicket different from most other web application tools is that it effectively separates the logic of the actual program from the simple HTML markup of a web page.

This week I set out to learn how to use Wicket in order to create a small web application for a simple stack Java program. With this program, a user can push items onto a stack, pop items from a stack, as well as clear the entire stack. Although the functionality of the program was quite simple, creating a web application for it did turn out to be more of a challenge.

Final Distribution Package for the Web App: stack-wicket-wolfft-1.0.1123.zip

Picture 1
final view of the stack web application

THE DEVELOPMENT PROCESS:
After reading some of the chapters of Wicket in Action as well as reviewing some actual examples provided by Dr. Johnson,  I started to grasp some of the basic principles of using Wicket. To my surprise creating an HTML page to interface a Java program is an extremely easy and clean process. Since there is no logic in the markup, the HTML page is left as simple as possible, and can be stylized and viewed all on its own.

On the other hand, creating a Java application that works with this HTML page is a bit more complicated. I wanted to create a stack application that would employ the use of forms, basic text output, as well as table output. In addition, I wanted to give each user of the application their own session in order to store their personal stack object and data. Luckily with Wicket, this task was not too daunting either. 

To do it all, I had to create an application class, then a page class, and then finally a sessions class. All of these components essentially run together to create the stack web application. Creating the page class was probably the most challenging out of all the classes since all sorts of different HTML elements were being updated on the one page at once. 

Another thing worth mentioning is the applications use of Jetty, a web server implementation that enables Java applications to run on a server. This was used to create a fully-working web application, though I more or less just reused code to get it to run.

DEVELOPMENT PROBLEMS:
I had a good time creating this stack application. I get real satisfaction from creating something that anyone can go out and use without having to run through a console. However, I did run into some small problems while developing it all. For one I had to figure out how to alert the user when they were trying to pop an empty stack. I fixed this by creating an error response text field in the page that would alert the user if they were popping an empty stack. Something else I could have done with this was only make the pop button visible when there were items in the stack.

Something else that I ran into was that initially the stack was presented in the table in list form, not stack form. This means the first item pushed was always the top item in the table. The way I like to thing of stack is the opposite of this and I wanted to make that clear on the page. I ended up creating a method in the Stack class that would put the stack in the right visual order right before updating the data to to table. It worked out quite nicely.

Also, one of the funny errors I kept getting was from CheckStyle on the basic Stack package classes. It simply stated:
Got an exception - java.lang.RuntimeException: Unable to get class information for @throws tag 'EmptyStackException'.
This was extremely confusing because I did not even alter the classes that the error was from. I was really stumped with this one and searched all over to try and figure it out. The problem ended up stemming from the build.xml file, which was not compiling all the classes, namely the EmptyStackException class. It was something small that I missed and when it was fixed it all worked nicely together.

LESSONS LEARNED
Creating this simple web app was more challenging than I initially anticipated. I spent a lot of time looking at the Wicket examples, trying to figure out the best way to create the application page, and still it wasn't working for me. Yet, now that it is all done, I feel I have a fairly good understanding of the Wicket framework. All the work spent on figuring out different ways to do things resulted in more knowledge of how things work. I do feel comfortable with Wicket and I know I will be using it in the future to create even more extensive web applications.

Wednesday, October 8, 2008

Further Exploration in Configuration Management

| 0 comments |

After working on a professor's project and creating my own stack project (link to past post), I thought it would be interesting to collaborate with another classmate using google project hosting and subversion. Usually when I've worked with others in the past, everything is planned out before each person programs or edits code in order to reduce code clashes and redundancy. Configuration management was never a part of these projects and I have to say it was a challenge sometimes. 


A good example of this was when I was working on the codeRuler project with Daniel Tian. He and I would send each other source files that often would not match up with each other, creating problems with the program on a whole. It was rather tricky to figure it all out. Even deciding who would create the final build was a bit confusing as we both had slightly different versions. It would have been nice to see how the workflow would have been affected with configuration management tools.

COLLABORATIVE SOFTWARE DEVELOPMENT
For this, I decided to collaborate with Jeho Jung, a fellow classmate also working on his own version of the stack project. After I was added to his project on google project hosting, and he was added to mine, we ventured out to verify each others project. I couldn't believe what happened next.

Upon check out of his source code, the ant verify process resulted in a 'BUILD FAILED.' And if you can imagine, the same thing happened with my code when he ran the verify script on it. I was really, really confused about it all since I swore I had verified it all before hand. However, what I failed to remember was when I slightly edited a test case before check-in. That's what screwed it up for my stack project. Jeho's project had a similar problem but his code had errors mainly from missing test cases.

Since we were working on each others code in pair programming style we each went through each project and fixed the problems accordingly. It all went smoothly and either of us were able to update the others project on google code. It's really cool how it all syncs up. I imported his project into eclipse and updated some of the javadoc comments. Then I checked in the changed files to his project repository and it was all set.

He did the same with my project and after verifying the build, everything was fine. I have to say it was an extremely streamlined process. For one, using CM tools makes working together on a project extremely easy and efficient. We could switch computers and still update the same project simultaneously. The subversion tools built into google project hosting make this super simple. Its great! It is also nice to get automated messages whenever a project you're apart of is changed (through the use of google groups).

INSIGHTS
Collaborative programming with another student really opened my eyes to the simple problems that can occur when programming by yourself. A big surprise for me was having a program that I thought could build successfully fail when another user was checking it. Who knows what sorts of things I could have missed on my own. It's really useful to get another programmer to work with so these things are found and fixed.

Collaborative programming also showed me the importance of using configuration management tools like google project hosting and subversion for development. Code review and production was instantly streamlined with the introduction of these tools. If only I had used these tools while creating the codeRuler program with Daniel Tian. Things could have been done much simpler and more efficiently. Configuration management is essential to collaborative programming projects.

If ever I work in a group setting again, I will not hesitate to use subversion and google project hosting. I'm sure my other classmates would agree. Overall, it really seems to me that the use of configuration management tools along with other tools like those for quality assurance, make for more stable builds and more efficient system. I plan to use them all in the future.

Tuesday, October 7, 2008

Experiences with Configuration Management

| 0 comments |

During my years as a computer science student I have never used configuration management tools, though I've known about them. I've never used them because they were never required in any of my classes and because frankly, I've never had a real use for them. Most of the programs I have written have been small and have been developed solely by me. But when are these configuration management tools essential for maintaining a project?

SUBVERSION
Before diving into subversion, I decided to think about some of the basic instances where using a configuration management program is useful:
  • When groups of people are working on a single project
  • When there is a system with multiple versions
  • When working on a large system
  • When projects branch of to separate versions  
Since I use Mac OS X, I could not use the 'ultimate' subversion client, TortoiseSVN available to windows users. What I did was install another good subversion client called SmartSVN. I found it extremely easy to set up, and after making a new directory on my system, I connected directly to the stack-johnson project on google project hosting. I then checked out the version in the online repository to get the most updated version of the program on my local machine. SmartSVN makes everything very simple and pretty intuitive. 

smartSVN
the smartSVN interface with the stack-johnson project view

To test out the other subversion commands I corrected some of the test code in TestStack.jav by adding @Test to some of the test methods. This is one of the first things I noticed in the stack source code and it definitely improved the system on a whole by enabling those methods to run in JUnit. After verifying that the project worked fine, I committed my change in TestStack.java and bam, my updated code was a part of the main line project.

That is what I think makes using a configuration management tool like subversion so cool. If many people are all working simultaneously to optimize some system, it makes things go really fast. Within a couple hours there were updated test cases and Javadocs in the stack program and it was much better than it was initially. Tools like subversion are essential for group work. It makes things so much easier. I can also see now how it is essential for versioning purposes. Its like an intelligent central backup, stemming from many sources.

GOOGLE PROJECT HOSTING
In order to get even more experience in using project hosting and subversion I set out to create my own stack project on google hosting. Google always impresses me with their different applications and technology. It seems like they have created everything anyone could ever need on the web (including this blog site!). In addition, everything is done so simply, while maintaining powerful functionality. Google project hosting is no exception to this. 

I went in and created my own personal project called stack-tylerwolff. It took about 2 seconds to do the initial set up and I was then ready to check in my program to the web. What was a bit
confusing was adding files to the project. I had to start up SmartSVN, check out the project into a directory (empty project), add files to be version controlled in that directory, and then check-in those files to google project hosting. This took me awhile to figure out but I eventually got it all to work nicely. Once everything is synced up to your local directory, check outs, updates, and commits can be done instantly.

Its really convenient that google project hosting incorporates subversion into their hosting infrastructure. On the project page you are able to view the source file directories as well as a changes list. Google makes it really easy to see everything that goes on with the program from start to finish. What's neat is that after adding Jeho Jung to the project, he was able to update and better the program from his home computer. It is really a great thing!

Overall, the hardest thing about creating a working project on google project hosting was creating a mailing list through google groups. I spent the bulk of my set up time trying to figure this all out. What I eventually realized was that I had set the group to be private, which meant group members (mainly codesite-noreply@google.com) did not have the proper permissions to post emails to other group members. When I fixed this problem, change messages were sent out to everyone added to the project and it was all good.

Subversion is such a great tool for working together on a project. Checking code in and out can be done instantly and getting updated project files is equally as quick. I can't imagine how one would work on a group project without it. In addition, google project hosting is so user friendly and easy to use. Creating projects and maintaining them through google is a smart idea. I can see now that the use of both can really optimize software engineering on a whole.

Monday, September 29, 2008

Code Coverage Using Emma

| 0 comments |

Emma is an open-source Java code coverage tool that I recently added to my collection of Java quality assurance tools [Ant, JUnit, CheckStyle, PMD, FindBugs]. What it essentially does is check that every line of code in the source files is run though using class, method, line, and basic block coverage methods. It can be a very handy tool for testing as it makes sure that every line of written code is tested (though there still may be bugs). It is another form of white box testing since it analyzes the internals of the program. 

To see how it all worked, I decided to run Emma on the stack system I worked on last week using the other Java tools. Initially, the method, block, and line-level coverage of the system was around 75%. For a small program like this, test coverage of 75% could be fully improved by adding more comprehensive test cases. It was my goal to get the entire program to 100% coverage. 

PROCESS & PROBLEMS
I decided to work on this exercise with another classmate Arthur Shum, to get a feel for paired programming. We both worked on our own computers but we went through everything together and resolved problems that arose. It turned out to be a very productive programming session. The installation and set up of Emma was very easy, just like the other Java tools. I was surprised at how nice the Emma html output is. The two classes Stack and ClearStack had color coded coverage markers - Green for covered code and Red for non-covered lines of code. This made it extremely easy to point out what needed to be tested. 

To get full coverage I had to go in and make more unit tests for the toString and getTop methods of the Stack object. I also had to make some new unit tests for the getTop method of the ClearStack Object. This turned out to be a rather simple task, but it was great because I got to write some more of my own JUnit tests. I feel a lot more comfortable writing tests with JUnit. 

The biggest problem I ran into during this whole process was having my correct code suddenly error in eclipse.  This would happen to me almost every time I made a change to one of my test classes. Arthur was having the same sort of problems with his project and eventually he found out that if you rename the containing directory each time, the problem was fixed. It was really a pain though. I just recently found out this was happening because I was running Ant (from a terminal window) and Eclipse simultaneously. Both were compiling the class files into the same directory and this was confusing the system. 

Eventually got 100% coverage in the stack project. Arthur did the same and it was all done rather quickly. Stack project with 100% code coverage: stack-tylerwolff-6.0.929.zip

One interesting thing I observed during this exercise was a line of code that produced a yellow coverage marker in the results. I noticed this happening in Arthur's code for his Stack class and it took us awhile to figure it out. After analyzing my test cases for that class we realized that he was not checking both cases for the if statement. To get full coverage, we needed to test all boolean cases, both true and false. This, I thought, is a pretty smart function.

However, I can see where getting 100% code coverage does not equal a fully tested, bug free program. Emma really only checks that all lines are tested. What would happen if some important factors were left out in an if statement? Or what if the system utilized a function that deleted something when it was supposed to only view it? All this would still get 100% code coverage if there were basic unit tests, yet it would still be buggy. I realize that it is not enough to rely on code coverage tools like Emma. Still, I think it is definitely a worthwhile tool to use on projects. It works quickly, efficiently and can improve the robustness of your code.

Bug Problems with 100% Code Coverage

| 0 comments |

Test coverage has many limitations in the programming world. When I first heard of tools like Emma I really thought using them would make my programs totally robust and bug-less. However after reading articles like this, and working on getting 100% code coverage with my Stack project, I am starting to think otherwise. Would it be possible to introduce a full fledged bug into code that gets full code coverage?

INTRODUCING A BUG
My programming partner Daniel Arakaki and I decided to create a version of our previous stack system that would have 100% coverage in Emma using the existing unit tests, as well as a significant bug that could ruin the system if it were ever put into real use. After contemplating it for awhile, we came up with a plan to introduce a bug by changing a basic function call in the getTop() function of the ClearStack class.

by simply changing this method:
  public Object getTop() throws EmptyStackException {
return this.top();
}
to:
  public Object getTop() throws EmptyStackException {
return this.pop();
}
we effectively introduced a bug into the system that would (using our current test cases) get 100% code coverage using Emma. We ran it through JUnit and Emma and sure enough it all worked fine. Final stack system with introduced bug: Download.

Imagine if this stack system was put into any sort of real use. There would be EmptyStackExceptions all over the place and if you ever did want to see what object was at the top of the stack, you would effectively screw up the stack structure. Any calls to pop after that would return a different object than expected. 

The funny thing about it is that all this could potentially happen just because of one wrong letter in the method (p instead of t). To put it in perspective, imagine if this bugged stack system was implemented on a vending machine. If there was a button to check item availability and a user pressed it, they would get a free item. In the long run the numbers wouldn't add up for the company supplying the vending machine and money would be lost. If a programmer bases all their tests on code coverage results, their code will be flawed. 

CONCLUSION
I think code coverage tools like Emma are very useful for programming. Code testing and optimization becomes more efficient, and it can at least help one to test their code better. The thing is, you cannot rely on them for all your testing needs. It was very easy to introduce a significant bug into the stack system and still get full coverage. It was only when I added another test case that checked for multiple getTop() calls that the problem was found. I, for one would not have though about this potentially being a problem in the original stack program. I guess it comes down to how thorough you want to test your code, and this cannot be fully based on code coverage. It is only a tool to help you with it.

In addition, another downfall of code coverage tools like Emma is that they cannot account for lines of code that should have been written, which means code that has 100% coverage could still have bugs. Overall though, I still think code coverage tools should be used to help in testing. They are quick and efficient and can really improve testing. I will definitely will use Emma as I write tests to my programs knowing all of this.

Tuesday, September 23, 2008

Using Ant/QA Tools to Build a Robust Program Package

| 0 comments |

As programmers there are many tools out there that streamline the writing process and optimize code. Some tools create all in one programming environments to work in (IDE's), some tools help you to build projects, and others do all sort of cool things that clean-up and optimize code. Previous to taking ICS413 I was never exposed to these technologies (apart from IDE's). I never knew the power these sorts of things hold in a programming environment. 

TASK 1
The main goals of this exercise were to 1) become familiar with the ANT build system, 2) become familiar with Open Source Java automated quality assurance tools, and 3) learn more about the build system and packaging standards for our ICS413 class. The first task was to simply download and install the specified Java tools on our system:
  • Checkstyle 5 Beta - checks source code mainly for layout issues based on a coding standard.
  • PMD 4.2.3 - Checks source code for things like bugs, dead code, overcomplicated expressions, etc.
  • JUnit 4.5 - A framework for writing and running automated tests.
  • FindBugs 1.3.5 - Uses static analysis of byte code to look for possible bugs.
  • Ant 1.7.1 - A Java based build tool. 'Make, but without Makes wrinkles'
In addition we were to download the source stack package to test these tools on. It turns out that this task was one of the more challenging parts of the assignment. After I downloaded each tool, I had to go and edit some environment variables on my machine so they would point to the respective tool. Since I use a mac I had to edit my .profile file to add some environment variables like this:
export ANT_HOME="/Users/tylerwolff/Documents/ICS/Tools/apache-ant-1.7.1"
export CHECKSTYLE_HOME="/Users/tylerwolff/Documents/ICS/Tools/checkstyle-5.0-be$
export FINDBUGS_HOME="/Users/tylerwolff/Documents/ICS/Tools/findbugs-1.3.5"
export JUNIT_HOME="/Users/tylerwolff/Documents/ICS/Tools/junit4.5"
export PMD_HOME="/Users/tylerwolff/Documents/ICS/Tools/pmd-4.2.3"
Luckily a friend in class helped me get to this point. Otherwise I would have been at a loss at what to do. I also needed to change the path to ANT 1.7.1. After I finally managed to finish this all, I ran some tests to see if I had installed everything correctly and it worked just right.

TASK 2
The default stack project was already set up with all the xml files needed for the ANT build system. All I had to do was go in and rename some of the variables to add my name to the project . The most complicated thing I had to do in copying the project was to go into the verify.build.xml file to remove the statements referring to the 'emma' tool which is not in use yet. I found the ANT xml files to be extremely easy to understand and decode. Its almost like an upgraded MAKE system. I guess thats why they themselves call it 'Make, but without Make's wrinkles.'

TASK 3
After copying the project, I worked on and finished fixing the problems associated with it during class, with the help of Daniel Arakaki. We used each tool, found the bugs or errors associated with the project, and continued on to fix the problems within the source code. All in all, I have to say it was a very streamlined process using the QA tools. They run instantaneously to produce a very readable page of errors. Although I was not surprised to see errors arise after invoking each tool, I was surprised at how easy it was to understand what the errors actually were. Many of the tools, like PMD and FindBugs even go a step further by linking the errors to full descriptions with examples. This made it really easy to fix some of the errors. For instance in the Stack.java file PMD suggested that instead of using implementation types like ArrayList, use an interface. I was a bit confused by this at first so I clicked the error link and it gave me a concrete example of what they mean and how to implement it. It's a great system!

The rest of the errors were checked and now the project verifies perfectly.
Finalized stack system: stack-tylerwolff-6.0.923.zip 

Overall I feel comfortable using these programming tools now. I don't think I will program anything from now on without them. ANT especially makes it really easy to compile and build entire systems. I like how you can use it to invoke quality assurance tools as well. Its so easy to go through and use these automated tools to better your program. I really think its a good thing to do. I love that fact that you can even learn from using these tools as they show you new errors and changes to make to them.