Friday, January 27, 2006

Simple Code Reviews Using Eclipse

Performing regular code reviews can be a real benefit to small and large development teams for several reasons. First, you can spot coding defects and logical errors before QA finds them. You'll have a much easier (and quicker) time fixing a defect found via a code review than through testing. Second, it's everyone's opportunity to check that the new code meets whatever coding standards or naming conventions you've set for the team or project. Finally, there's no easier way to rapidly educate the other developers on your code changes especially if you add some simple comments.

Code reviews don't have to be laborious or require meetings. I use Eclipse/CVS to help me with this task. Here is the basic process.

On checking in code

  1. Use Eclipse's Change Sets to define small atomic units of change. Try to keep the units small, but not meticulously small.
  2. Write good check in comments. Ideally, develop a standard on what goes into these comments.
To do the code review

  1. Open eclipse's snchronize view.
  2. Click synchronize to see the files that changed.
  3. Enable Change sets and view the authors/comments of the checked in code.
  4. Clicking on an individual file will open eclipse's diff tool. From there, you can now see all the code segements that were modified.

That's pretty much it. It's not fancy, but it works!
continue reading "Simple Code Reviews Using Eclipse"

Thursday, January 26, 2006

ClickStream Analysis Tool

For those of you that want a free/easy clickstream analysis tool, have a look at StatViz. If you're running Apache and using the standard log format then plugging in this tool is very easy.

Setup
  1. Download and install GraphViz. There's an RPM for linux...
  2. Download and install StatViz in a directory. It's basically one php file. The README file will tell you how to customize the configuration file and run it.
  3. I don't have too many PHP apps running so there's a couple of other things you may need to do. First, you'll need PEAR:Config. Once you have this, uncompress/untar it the easiest thing to do is move it Config.php and the Config dir to /usr/share/pear. Second, statviz takes up a lot of memory so you may need to increase the memory_limit configuration parameter in your /etc/php.ini
That's pretty much it...

Basic Running

You can run it using

./statviz.php --config configfile

and then create a gif file of the output by doing something like

dot -Tgif -oOutputGifFileName InputDotFile

If you put the output gif file in a web accessible dir then you'll be able to see it from your browser.

Things To Look For

There are a number of things you'll need to consider if you want accurate results:
  • Make sure you look at the bot extensions and make best attempts to get these filtered out.
  • Make sure you have all non-pages (graphics, js, css) filtered out.
  • If possible, try to filter out requests from internal users. Statviz doesn't have a filter for this, so I just scrubbed out of the logs myself using a grep -v.
  • If you're site has long URL's, you will most certaintly want to clean them up before processing. The tool allows you to create an alias file, but you may need/want to do some log scrubbing on your own.
  • Play around with the GraphNReferrerPairs parameter. You can get a lot more detail on site activity with higher numbers, but the graph becomes the graph then becomes a lot more complex to digest. If you decide on a large graph, you may need to modify the source and change the size of the graph. It defaults to 10, 8 and there isn't a parameter to configure this. I changed it to 20, 16 for most of my small graphs (GraphNReferrerPairs <>) and to 40, 32 for larger graphs.
  • Very long URLs are going to be a hassle, especially if they come from external referrers and out of your control. I put in some checks in the code to clip the very long URLs.


Automating


I've automated a couple of things on my site:
- A report that updates hourly on today's activity.
- I archive a daily gif file. (I will add weekly and monthly in the future).
- I have a 'full report' that shows activity for the last 30 days. I update this daily.

I'll put out another entry with a quick 101 on interpretting the results.
continue reading "ClickStream Analysis Tool"

Tuesday, January 17, 2006

Sites I Worked On

Someone sent me an email the other day and asked me what sites I managed. While not a complete list, here is a small sample:

  1. TripConnect is a site where you can share travel advice with people you know. You can post destination and hotel reviews then invite friends into your network and ask them to update the site with their favorite destinations. The next time you're planning a trip, you can use TripConnect to find friends that have been to the destinations your researching and you can ask them for more detailed travel advice.
  2. Abracat and other sites like the Register Guard's Classifieds run a product called 'c2', a classified ad ASP engine that PowerOne Media sells to newspapers.
  3. I worked on several other products/sites for PowerOne Media. For example, CTCentral runs on a content publishing system called Zwire, and NowHiring.com is a site for searching employment ads from hundreds of newspapers. Some other sites included back end tools for their National Advertising product and infrastructure for their CarCast product that you can see running on sites like IndyAutos.
continue reading "Sites I Worked On"

Simple Prototyping in Struts

After playing around with several viewing technologies (jsp, tiles, velocity, jstl) and many approaches for managing the business/data tiers, I've settled on one approach that I think is the 'best' (or good enough for me :-) ) for prototyping data access pages.

What is a data access page?

Simply put, it's basically a data driven page. Pull data from somewhere, do a bit of processing/logic and render it to the user.

A simple recipe for prototyping:

I'm using jstl to get my data and displaytable to render the data. This combination lets me prototype a page using only 3 tags:


// Set the data source
<sql:setDataSource dataSource="[DATASOURCE]"/>


Use the data source name in your [application].xml file


// Do the query
<sql:query var="results">
[Your Query Goes Here]
</sql:query>


Once you do that, you can use display table to render the results





// Open the table
<display:table style=name="pageScope.results.rows" >
// If you need to get access to the object, do something like this:
<% SortedMap m = (SortedMap) row; %>
// Here is a simple way to render one of your columns:
< display:column property="[columnName]" title="Simple Column"/>
// Or a more complex way (in case u need to do processing
<display:column title="Complex Column">
<%=(String)m.get("ColumnName")%>
</display:column>
// Don't forget to close your table!
</display:table>


Why this works so well

Basically, the key to prototyping is speed and flexibility. All the data and logic for this prototype is in one file. Tweak the query and the UI as you need to... Once everyone is happy with the results, then you can review the prototype and migrate the code to the proper places.
continue reading "Simple Prototyping in Struts"

Sunday, January 15, 2006

J2SE From Tomcat

I discovered two other issues when upgrading to the J2SE 1.5 compiler for JSP's on Tomcat:

1) You'll probably want to set

<init-param>
<param-name>errorOnUseBeanInvalidClassAttribute</param-name>
<param-value>false</param-value>
</init-param>

in the jsp declaration in TOMCAT_HOME/conf/server.xml if you want to use jsp:useBean with generics. For example:

<jsp:useBean id="users" class="java.util.ArrayList<UserVO>" scope="request"/>

2) The ant compiler seems to be a lot more picky than Jasper. For example, I had a bunch of import statements on classes that didn't exist in my classpath. Jasper has no issue with the issue and the pages ran fine w/ this import, but Ant reported these as errors whenever the page compiled. For this reason, I strongly recommend testing every page before deploying this to production environments.

I will continue posting new issues that I find on this Blog. If you have any that you've found, publish a comment here.
continue reading "J2SE From Tomcat"

Monday, January 09, 2006

Upgrading Tomcat and Eclipse to J2SE 5.0

I just finished upgrading one of my apps to J2SE 5.0. The docs on this are somewhat fragmented so here is a step by step guide for upgrading Tomcat and Eclipse to this version of the JVM.

Assuming you're on Tomcat 5.5 and Eclipse 3.1

1. Download J2SE 5.0 form Java/Sun site and install.
2. Change Tomcat's classpath to use the new compiler:
- On Windows, this can be done by opening 'Configure Tomcat' from the Start Menu/Apache Tomcat 5.5 menu, clicking on the 'Java' subtab and changing the JVM location.
- On Linux, you can do this by just changign the JAVA_HOME env var for the user that starts/stops tomcat.
3. In Eclipse, Open Window->Preferences, then click on Java/Compiler in the preferences menu. Change the 'Compiler Compliance Level' to 5.0
4) Check your build.xml (assuming you're using ant to build) and make sure that you have the following parameter set correctly: source="1.5"
5) Do a full build and test your app!

Next, if you'd like to use 5.o features in your JSP files:

6) add tools.jar from your JAVA_HOME/lib directory to TOMCAT_HOME/common/lib
7) Remove jasper-compiler-jdt.jar from the TOMCAT_HOME/common/lib dir and replace with ant.jar. I used Version 1.6.5 available from the Ant/Apache website.
8) You'll need to edit your web.xml file in TOMCAT_HOME/conf and add the params in red.

<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.5</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>


9) Restart tomcat (Better safe than sorry)

Done!
continue reading "Upgrading Tomcat and Eclipse to J2SE 5.0"