Wednesday, May 25, 2005

Technical - "Spring: A Developer's Notebook"

This book is from a new O'Reilly series, called "Developer's Notebook". The idea behind the series is to present some piece of software or a tool in a way a developer might want to see it. Basically, with all the fluff removed and just pure technical discussion on how something should be used. with lots of coding examples. The book even looks like a notebook, with fake coffee stains and post-it notes on the cover. So far I have seen maybe five or six books in this series.

The book I read is "Spring: A Developer's Notebook", which covers the Java Spring framework (I know, a big suprize). What is the Spring framework? The official, buzzword compliant, definition is that Spring is a "lightweight container". In plainer language, Spring is an enviroment for running Java applications. Spring provides number of services (such as security, transactions, remoting etc) that are often provided by the heavy weight J2EE application servers (like Weblogic or Jboss), but without forcing your application program into a heavy J2EE type structures (EJBs etc).

Spring gains a lot of its power from few very simple concepts. The first one is a design pattern called Inversion of Control (IOC) or sometimes called Dependency Injection. This is a fancy name for using Java interfaces to decouple components of your system. Spring provides facilities where interface implementations are configured via XML, and objects are connected by Spring during system initialization. This connecting is called "dependency injection" - I think Martin Fowler came up with this term. Don't blame me.

The use of IOC is illustrated to the n-th degree throughout. The book consists of a graduated example. As you are reading the book you can actually implement the example and have running program at the end of each chapter (I didn't do this). The book's example is a system to manage a bicycle rental shop and the class that implements the storage of bike information is implemented in several different ways - depending on how we plan to store the data - and is "injected" into the system at startup time.

Another big advantage of using Spring, is that the application objects are POJOs ("POJO" means Plain Old Java Ojects - who comes up with these?!), that is they are not required to implement any weird interface or extend any container classes (as you would under Weblogic let's say). This makes automated unit testing a lot easier. Again, nearly every chapter includes some unit test examples (see JUnit and continous integration if you want to know more about testing).

The other big part of Spring, that makes it much easier to use, is the AOP framework (AOP stands for Aspect Oriented Programming). With AOP you can insert code into exiting system to do stuff like manage transactions, or handle security, without the need to touch the basic objects of the application. One of the central ideas of AOP is that a call to method can be intercepted and something can be done either before or after the method runs. The cool thing about the Spring's AOP is that although the interceptor code has to be written in Java, the insertion into the system is done via XML configuration.

In any case the good thing about "Spring: A Developer's Notebook" is that it contains only the meat of the subject. There is no unnecessary narrative on the history of Spring, or definitions of XML, or what OR mapping is. Things that you'd expect the reader to know. Instead you have a worked out example that demonstrates the key concepts of the framework, and if you work through it yourself at the end you will gain a deeper understanding of the topic.

After having been stuck with needing to read 400 page technical books, which are 80% useless fluff, it's a pleasure to read a book like this. But again, since this is an O'Reilly series I'm not suprized. I already started to look at developer's notebooks on "Hibernate" and "Java 1.5".

Tuesday, May 24, 2005

Science Fiction - "Paycheck"

This is another story by Philip K. Dick, which was used as a base for a movie by the same title. I recently saw this movie (picked up a DVD in discount bin at Wal-Mart), and found the movie pretty bad.

The story was little better. The plot is about a mechanic who gets a job at a secret company for two years and at the end his memory of the two years is erased. When he goes to get his paycheck instead of money he gets a bag of , what seems like useless, trinkets. At first he is upset and puzzled, because it is he himself who prepared those objects.

In the rest of the he finds each of the trinkets very useful and realizes that somehow in his job he had been able to forsee the future. Turns out the technology the secret company was working on is called a "time scoop" - a device that lets you retrieve objects from the future.

The interesting difference between this story and the movie, is that in the movie the company that made the machine was evil and was destroyed by the hero. In the short story, the company is one of the last bastions of freedom, waiting to overthrow the bad goverment. In the story the hero has to avoid the Secret Police, who want to find the location of the hidden plant.

In the end the hero winds up working for the company, to help save it and save himself from the goverment.

Again, as in "Minority Report", the technology described is bit skewed. There are rocket cars, but computers are not mentioned.

Monday, May 16, 2005

Science Fiction - "The Minority Report"

Few months ago I watched the movie by the same title and since then I have been wondering how far from the original story has Hollywood strayed. "The Minority Report" is a short story by Philp K. Dick that was the basis for the movie.

The basic story elements include Pre-Crime police force, three pre-cogs, who predict the future crimes, and what appears as a false prediction about the story's main character. But this is where the similarity to the movie ends.

Whereas, in the movie the events lead to discrediting of Pre-Crime, in the story the main characters commits murder in order to preserve Pre-Crime police department.

The title "The Minority Report" refers to the dissenting prediction of one of the three pre-cogs (as in the movie), however, and this point is made strongly in the story, there is no majority report - all the reports are "minority reports". Because they never really agree that precisely. In the case of the story's hero, the subsequent reports are affected by his knowledge of earlier ones.

The story itself is pretty short, maybe 30 pages, and I read it over two evenings.

One funny thing about the story is how it gets technology wrong. The story has flying cars, but the computer still produce their output on cards.

"The Minority Report" is one of the stories in "The Philip K. Dick Reader". I bought it because I wanted to read all the stories that were basis for the movies: "Total Recall" and "Paycheck". When I read them I will report further.

I presume that you know that the movie "Blade Runner" was based on Philip K. Dick's book "Do Androids Dream of Electric Sheep". I read that book ages ago.