Spring is hip these days, so I decided to learn a bit more about it. I had used Avalon a while ago, I was attracted by its design by component and the way it seemed to lay out a proper infrastructure to build a server application. In the end, I was a bit disappointed, it required a bit too much glue code for my taste and did not provide that much in exchange. I don’t remember if, at that time, it was advertised as IoC (Inversion Of Control) container. This experience is one of the reasons why I did not jump on the Spring ship.
I have read 3 books, here is what I thought of them, briefly:
Spring: A Developer’s Notebook, by O’Reilly: I enjoyed reading that book, because it is well written and has a good structure. It explains what is dependency injection by doing it without Spring, with Spring. But for a more complete understanding, I would recommend Fowler article. There is an interesting chapter on Swing with Spring. Minor drawbacks is that it does not talk about Spring Timers and has very little on Remoting. But I would recommend that book.
Spring In Action, by Manning: I was disappointed by that one, because there is not much more information than in O’Reilly, it is a bit less practical to use. While it is a bit more detailed than O’Reilly, I did not find the extra information very useful in general. Remoting is better covered here than in O’Reilly, but there is nothing on Swing.
Professional Java Development With The Sring Framework, by Wrox: I liked that one better than Manning, but again information inside is very similar. I find the explanations more complete. Inversion Of Control is well presented (it is even comparing constructor injection with method injection). It gives examples of alternatives to XML configuration. Remoting is covered in greater details than Manning. I would recommend it over Manning anytime, and if it included a Swing chapter, I would recommend it over O’Reilly as well.
You can wonder a bit why there are 3 books on Spring, that similar. I believe there is space for other intelligent presentations of Spring. Subjects are often treated superficially. For example, look at the Fowler article versus the best chapter about IoC, the one from Wrox, and you’ll see how much more detailed it could have been. I find it a bit shocking since IoC is the basis of Spring. It would have been good to see a book explaining why Spring chose that particular design over another, for the main features, and presenting alternatives better. I would also have welcomed a book explaining the use of maybe just a few Spring aspects, but in the frame of a big, commercial application. For example after reading those books, it is not immediately clear to me what are Spring benefits when using Swing support versus other solutions. Another critic is that all those books were written around the same time, and are sometimes already obsolete. None of them describes Spring JDK 1.5 support (for transactions or JMX or metadata). The official free Spring reference book seems better in many ways.
Those books showed me Spring could be useful in some projects:
if you want remoting
if you want to promote clean code, then you can promote the “Spring way”. It is a good one.
if you want to use JSF. Spring makes JSF easy and natural to use.
On top of it you get AOP for easy debugging or profiling, which is always useful at some point.
I am not convinced about Spring when it comes to:
JDBC or database use: while Spring has a well done framework, Hibernate or iBatis have a very good API that makes Spring abstraction useless.
MVC: it is does seem that much better than alternatives, nor much less intrusive (OK you can test it easily). Anyway I am not that big a fan of web MVC after having seen real world .NET projects without strict MVC well maintainable. I find the JSF backing beans at least as good and more flexible. Continuation frameworks are interesting too, but I am worried of their performance impact and scalability.
Transactions: I just don’t think manual transactions are that bad or ugly or less maintainable. But using Spring for them is not necessarily a bad idea either.
To me, the main alternative to Spring, and a very good one, is JBoss. I will elaborate on that subject later in another post.
Today, I just found out about DPML Transit, it is a small framework that helps you build plug-ins based software. It seems to work a bit with DPML Magic, their build system based upon Ant. Both are quite interesting, since in big projects, you often end up with a packaging per component (which DPML Magic seems to make very simple) and a versioning of those components. DPML Transit allows then for an efficient way to look up a particular version of one component.
I have not heard of DPML before, they seem to write useful software. Has anybody used those frameworks already?
The book Java Puzzlers is quite good. I don't think anyone can get every puzzle right. This shows again how you can very easily make someone fail interviews if you ask too silly questions. I suppose that if people were asking those questions they would not expect the right answers, but study the candidate reactions.
Here is a sample:
public class DosEquis { public static void main(String[] args) { char x = 'X'; int i = 0; System.out.print(true ? x : 0); System.out.print(false ? i : x); } }
This will output "X88". Obviously this is not good code, which is precisely one of the book objectives: to show how bad some practices can be. But at the same time you learn a bit more about the Java language and its possibilities. In the latter chapters they have more interesting puzzles.
I am currently reading a Prolog book Artificial Intelligence Through Prolog, I have been doing a bit of Prolog when I was very young and wanted to refresh my memory a bit. It is a very interesting read, especially when I take the viewpoint of our current application where no ACID compliance is required.
It seems to me that all the logic we coded to parametrize SQL queries and construct them dynamically could have been avoided if we had chosen Prolog as Prolog expressions would have been very natural to use in our project. With Prolog, there is no need to think about joins, type of joins, SQL syntax. It is at the level just higher. I wonder very much why Prolog did not become more mainstream as it seems to solve some problems in a much nicer, natural way.
Here is a short example to get reviews of things by user or by user and tags or …:
In bamboo-dht, a distributed java hashtable project, the main developer, Sean C. Rhea, advocates the use of Curries and Thunks (of LISP and ML). He wrote an interesting and valuable document, Async Tutorial, presenting a use of it. I will present the concept here shortly:
public interface Thunk1<T> { void run (T t ) ; }
Thunk1<Integer> intThunk = new Thunk1<Integer>() { void run (Integer i ) { System.out.println( i ) ; } }
public static <T> Runnable curry(final Thunk1<T> f ,final T t ) { return new Runnable () { public void run ( ) { f.run ( t ) ; } } ; }
Runnable print42 = curry( intThunk , new Integer ( 42 ) ) ; print42.run ( ) ; //prints 42 to standard output
So it is a very clever way to have a callback in java. Very clever because you can declare your code to take only a run(), and pass any parameter in it by using a curry. It is very simple to use, even if the small framework around it can scare some people.
However neat the idea is, I am not sure it is practically useful. Sean C. Rhea used that because he did not want to use "unnecessary" instance variables. Ok, but the curry is still creating another instance (actually 2 but one could be static), is the overhead of a class instance without variables that much more than one with variables? And there is another way, without the Curry framework: Runnable print42 = new Runnable({ public void run() {intThunk.run(new Integer(42));}}); print42.run();
This is actually exactly what the Curry framework would do behind the scenes. The Curry framework makes it a bit more elegant, but I am not sure if that's really more readable for most programmers. I would personally advise the traditional way, use instance variables.
“dismal interview where I asked about the candidate’s experience with porting a J2EE application from WebLogic to WebSphere (which was listed on his resume). The candidate said that it was very easy and he just deployed his application with no problems or changes necessary, he had no changes made for the application to run properly. This was one of many bad signs for the candidate.”
I disagree. I would even use his example to show that the portability game is more about configuration and packaging rather than about anything else so that many developers would in-deed not see a big deal into porting an application to a new application server.
You can make a port to Websphere or Weblogic quite transparent if you externalize the JNDI strings (for example in properties file), which is anyway what you should do. Repeating a same string everywhere in your code is bad practice in Java.
The most problematic is usually the packaging, weblogic and websphere, for example used to manage the jar dependencies a different way (websphere being very strict, weblogic a bit more practicle). And actually JNDI settings, DataSources and Security should boil down to packaging problems, which is why, I think, your candidate did not know of any problem unless he worked on the packaging of the app.
Recruitment is no easy task. I did not find yet a magic formula for it, except maybe, try the person for a month. Personality is more important than knowing technical details. I am not sure if one can see if a person is serious, rigorous, and reasonably fast in an interview.
I took some time to continue my little JavaBlogs analysis, I now have a page summarizing the top 10 most read blog entries in the last week. The page is generated every 24h (this is why there is no ‘best progression’ as of today).
I also fixed some bugs related to HTML in RSS2. I understand a bit better why a RSS 1.0 co-author decided to remove the possibility of HTML descriptions for RSS 3.0. It often does not make sense to keep all that information about styles, fonts, etc. from different sources. What I do is rewrite the HTML, allowing only b,i,a,p,br tags, with the style information stripped. I found the open-source htmlparser java library quite helpful to achieve that.
Mai 2006 Update
I now post the top10 every week to my blog, I wrote a little piece on how to interact with Blogger API in Java. This avoids me having to maintain an extra site.
HTTP requests handling is done using commons-httpclient library to have more control over how http requests to javablogs.com are performed. commons-httpclient is also useful to post to blogger. About the parsing with htmlparser, I changed the way to do it, I used to only use a simple Lexer, but now I changed to using NodeVisitor as it allows me to parse with finer granularity more easily, even though it is probably slower. I needed that to update href elements to that they are XHTML compliant.
I was a victim like many other of spams in comments. It’s stupid for people to do that on Blogger.com since the links on comments can not be referenced by search engines (they have some special ‘relative’attribute for that) and improve pagerank.
Fortunately Blogger.com provides a word verification step if you want to avoid random spam. However I am a bit disappointed that they force Blogger.com users to do that word verification as well. This time I find it stupid from Blogger.com. They have control on their users, so they could ban spamming users, and for everybody else on Blogger.com, this would be just one less step. I am always a bit annoyed at measures that solve a problem caused by a hand of people by making it more annoying for the majority.
I was wondering what blog entries were the most interesting on Javablogs. I decided to write a small application to do that. It was not much more complex to put it online for others to look at as well. It is currently running on http://gopix.net:8081/javabuzz
It also presents Javablogs a bit differently (I like it better that way).
Please note that it is just the result of a 1 (full) day of work currently. I hopefully will have a bit of time to improve it. For example I’d like to add some graphs about popularity, some weekly stats, and comments in blog entries.