Sunday, May 04, 2008

GenericDao 0.9.5

The 0.9.5 version of GenericDao is now available. This provides the biggest leap in functionality yet with enhancements including support for JDBC and pure SQL (along with Hibernate) and new search methods which use a generalized Search object to make it easy to control restrictions, limits, ordering and bascially everything you would want to put in a search for an object.
For anyone unfamiliar with the package it is mostly a bunch of convenience code to make it a little easier to have ORM like functionality and not have to write the same boring create/update/find/delete methods over and over again. It also provides a simple and extendable interface for working with persistent objects.
I am using the new version to replace the previous hibernate usage in a couple of projects and things seem to work quite well so far. The new version builds on some of the Apache projects like BeanUtils, Google projects like Guice, and the Spring Framework.
I hope to add in support for DDL generation using Apache DDLUtils in the next release.

Download (Maven2):https://source.sakaiproject.org/maven2/org/sakaiproject/generic-dao/
Maven site: https://source.sakaiproject.org/maven2/org/sakaiproject/generic-dao/site/
Javadocs: https://source.sakaiproject.org/maven2/org/sakaiproject/generic-dao/site/apidocs/

On a related note, this release was made using the Maven 2 release plugin which made the process very clean and easy. I recommend it highly.

Wednesday, February 27, 2008

Subversion Keywords

I finally got around to putting in SVN keywords in some of the files for the Evaluation System project. It took me a little while to figure this out but they don't start working automatically. You have to take the extra step of telling Subversion (via properties) that you want it to actually do the keyword substitution. Luckily the steps are pretty easy once you figure it out.

1) Add some keywords to your files like so:
$Id$
$URL$

2) Run this command from the base directory of your project (this will add all the keywords, just remove the ones you don't want from the string):
svn propset -R svn:keywords "Date Revision Author URL Id" .
3) Commit the code (this will take awhile because it is going to commit a new revision of every file in your project). The keywords will be replaced and look more like this:
$Id: EvalConstants.java 46025 2008-02-27 13:01:48Z aaronz@vt.edu $
$URL: https://source.sakaiproject.org/contrib/evaluation/trunk/$


Disappointingly this will not work for all files going forward so you will have to reapply this for new files or just do the whole set every once in awhile.

Sunday, January 27, 2008

Silverlight

I was roaming around the web and ran into a web application that used Silverlight this weekend. I did a little investigating and this weems to be Microsoft's answer for Flash and Rich Internet Applications in general. They make a lot of interesting claims about cross browser compatibility (IE, Firefox, and Safari) and compatibility with existing backends and AJAX. The big score for it though seems to be the claim that it is fully accessible and that the toolkit helps you make your apps more accessible and l10n. Overall, it looks pretty compelling and fairly easy to learn so I plan to keep an eye on it and see where it goes.

Main websites:
http://silverlight.net/
http://www.microsoft.com/silverlight/

A really cool use of Silverlight:
http://www.microsoft.com/silverlight/halo3.aspx

A blog/analysis of it from a developer prespective:
http://www.gskinner.com/blog/archives/2007/05/a_flash_of_silv.html

A demo/interview of Silverlight on Youtube:
http://www.youtube.com/watch?v=JEUrQEj6Sd4

Linux related project (Moonlight):
http://www.mono-project.com/Moonlight

Related (competing) projects:
Adobe AIR: http://labs.adobe.com/technologies/air/
Google Gears: http://code.google.com/apis/gears/

Monday, December 24, 2007

Working with Twitter

I have been playing with Twitter a little bit recently. It is a service that allows you share what you are doing with people via little messages. I can just be used for fun, but it can also be a valuable way to keep up with coworkers and colleagues. Updates can be sent via the website, IM, or even SMS texts from your phone.
I have been experimenting with the facebook integration and it is pretty good (via the TwitterSync app). This is the best way I have found to keep your facebook status synced up with Twitter.
I am most curious to see how use of twitter in a professional setting evolves. I think it could be a great way for split project team members to keep up with each other.

Saturday, December 22, 2007

Strings and StringBuilder optimizations

I keep running across code like this:
public String THIS = "this ";
...
StringBuilder sb = new StringBuilder();
sb.append(THIS);
sb.append("is ").append("a ");
sb.append("test: ");
sb.append(5);

It is hard to read and maintain, and wastes the time of the developer who wrote it because there is basically no benefit to writing it. The (Sun) Java compiler will do some optimizations which end up allowing coders to write nicer looking code and avoid lots of extra typing or copy and paste. Let's rewrite the same code the way we would like to if we were not trying to over optimize.
  String test = THIS + "is " + "a " + "test: " + 5;
That's easier to read and the compiler turns this into a StringBuilder anyway. It is easily prove n by runing this code through a debugger and tracing it.
There is another related trick that the compiler will do for Strings.
  String test = "this " + "is " + "a " + "test: " + 5;
That becomes "this is a test: 5" in the bytecode (this is in the language spec). Very easy to read and zero cost at runtime.

As always, the old rule of thumb applies. Always optimize last (or never). Readable and maintainable code is far more important that a minor optimization which possibly saves a few nanoseconds (and in this case saves none).

Before anyone gets the wrong impression, there are perfectly viable cases for writing StringBuilders in your code. Creating a string from a large number of smaller strings within a loop is the most common use case. For example:
StringBuilder sb = new StringBuilder();
sb.append("Counting: ");
for (int i = 0; i <>
sb.append(" ").append(i);
}
String test = sb.toString();

In this case, using a single string and writing += would be more costly and should be avoided for any code that will run often.

NOTE: There is a pitfall here that one can fall into fairly easily. This example of what NOT to do shows how easy this is:
StringBuilder sb = new StringBuilder();
sb.append("Counting: ");
for (int i = 0; i <>
sb.append(" " + i + " ");
}
String test = sb.toString();

In this case, there will be a new StringBuilder created for each iteration through the loop. Do not use "+" concatenation with variables inside the loop (as shown inside the inner append above). This will end up producing another StringBuilder if there is a variable (it is fine if you are using constants). The loss from the creation of many additional StringBuilder objects will offset the gains from using the outer StringBuilder.
sb.append(" " + i + " ");
is efficiently written (when inside a loop) as:
sb.append(" ").append(i).append(" ");

The rule of thumb I use is that if I am concatenating strings on a single line of code then I use "+", otherwise I use a StringBuilder. I sometimes break that rule if I am just concatenating on 2 or 3 lines and the code would be more readable if I used "+" (since the savings are so small in that case).

For those of you runing Java 1.4, the optimization is still there but uses StringBuffer instead.

The key takeaway here is that writing readable and maintainable code should always be a priority over writing optimized code and this is one case where the compiler makes that a little bit easier on the developer.

A few helpful related links for more in depth study:
http://nicklothian.com/blog/2005/06/09/on-java-string-concatenation/
http://java.sun.com/developer/JDCTechTips/2002/tt0305.html
http://www.precisejava.com/javaperf/j2se/StringAndStringBuffer.htm

Saturday, December 15, 2007

Scaling Java with Grids and Clouds

There has been a lot of talk about using grids and spaces to handle large scale java applications at The Spring Experience 2007. The compelling thing about this for me is the idea that these applications allow architects to abstract the concept of clustering. Developers can effectively program as if they are running on a single server (with some minor APIs here and there depending on the solution). Most solutions scale up very well and provide failover support.

These solutions are being recommended as production ready solutions and apparently large companies (like banks) are already using them in massive scale production. It will be interesting to see how these impact Java enterprise development in the future.

Here are some of the solutions I heard mentioned at TSE 2007:
Terracota
OpenSpaces (API/aggregation site)
GigaSpaces XAP
Coherence
ObjectGrid

Friday, December 14, 2007

Spring Dynamic Modules

Adrian Colyer did an incredible demo of Spring OSGi at The Spring Experience on Friday, 14 Dec, 2007 to show the things that are up and coming. The demo included a 3 layer app (web, logic, dao) running with each layer as a separate module in OSGi. During the demo he intentionally shutdown the logic module, clicked a link on the web page, restarted the logic module, and then went back to the page which had magically worked without failing. Apparently Spring OSGi will proxy the layers until a timeout is reached or the module can restart. This allows some amazing things (like upgrades without server shutown). It can also control access to the modules so they can effectively operate in a hierarchy. I think they said it should be released in a few months.

On a side note, Adrian and Rob did a great keynote with some singing and roleplaying. It was easily the best keynote I have ever seen. Cheers to all who planned and executed it.

Thursday, December 13, 2007

The Spring Experience and RSF


I am attending the Spring Expereience in Hollywood, Florida this week (Dec 14, 2007) along with Antranig. It is exciting and scary to be around so many really great developers. It feels like everyone we talk to is doing something impressive and advanced with Spring. It is pretty intimidating to be around and talk to all these really great developers.

The sesssions have been really great so far. It is really hard to decide which sessions to attend because there have been a few slots where I wanted to attend all five talks. The presenters have actually written code in front of people which is great to see. I have had a chance to learn about the new Spring annotations, AspectJ, @MVC, and Testing. The material is advanced but that is what I want.

Antranig and I presented a rapid fire session on RSF. It was a one hour introduction to the goals and basics of RSF. We had a bit of technical trouble and the talk before us ran long but overall I felt really positive about the session. There were lots of good questions and we had about 25 people in the session. We even got a compliment on the wiki and documentation. I hope we will have a chance to talk with more people about RSF during the remainder of the conference.

Tuesday, October 16, 2007

Validating CSS online

I recently had a problem with a webapp where things were showing up but I could not figure out why. The CSS seemed correct at a glance but someone else had written it so I was not very familiar with it. After struggling for awhile I did the smart thing and asked Gonzalo Silverio if he had any ideas (which of course, he did). He pointed me to this awesome CSS validator at http://jigsaw.w3.org/css-validator/. You can upload a css file or simply provide a URL to the file and it will give you a nice little report that tells you what is wrong.
A similar service for validating your markup is available at http://validator.w3.org/.

Sunday, October 07, 2007

Roadmaps, Kernels, and Community?

There has been a bit of traffic on the mailing lists about Kernels and Sakai community processes recently. I personally hope that it will encourage more open communication in the community and more transparency around decision making. I have high hopes that some of the proposals I have posted in the Sakai Dev space on Sakai Confluence will spark conversations and encourage people to get involved in various framework improvement efforts.

In particular, I am hoping the following things are worked out BEFORE or AT the Sakai conference in December.
1) What does the Sakai Roadmap look like?
2) What is a framework team? What does it do? Who are the initial members?
3) How does the voting process work in Sakai and what kinds of things should be voted on?
4) Do we have a Sakai Kernel and if so, what does that mean (what is it)?
5) Should we have a code approval process for the Sakai framework and what should it look like?

What are the right answers to these questions? Frankly, that is outside my core area of expertise which is mostly designing and writing software. I have some proposals out there in the hopes that someone smarter will come along and rip them apart and replace them with something that is better. Even if that doesn't happen, I hope they will at least encourage discussion. Isn't that how we arrive at decisions that will benefit us all as a community? I mean, we don't really need someone to make all the decisions for us and tell us what to do... do we?