Thursday, September 29, 2005

Interesting Plug-In Framework - DPML Transit

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?

Tags: , ,

Interesting Plug-In Framework - DPML Transit

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?

Tags: , ,

Wednesday, September 28, 2005

Java Puzzlers - Can you figure this out?

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.

Tags: , ,

Java Puzzlers - Can you figure this out?

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.

Tags: , ,

Monday, September 26, 2005

Is Prolog Better Suited Than SQL?

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 ...:
  1. let's define some facts:
    • is_tag(tag1, user1, thing_id)
    • is_tag(tag2, user1, thing_id)
    • ...
    • review(user1, thing_id, description, extended, date)
    • ...
  2. review for user "user_x"
    • ?review(user_x, THING_ID, DESC, EXT, DATE)
  3. review for user "user_x" with tag "tag_y"
    • ?review(user_x, THING_ID, DESC, EXT, DATE), is_tag(tag_y, user_x, THING_ID)
We could imagine some better ways to lay out information. This is just a first draft.

Now of course, Prolog does not necessary makes sense for us because:
a) We already have it working in SQL
b) SQL is much more used and should therefore be more tunable, stable, etc.

Still the Prolog way of things is interesting and powerful. We could have written a code with a logic near Prolog instead of our custom code.
Tags:

Is Prolog Better Suited Than SQL?

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 ...:
  1. let's define some facts:
    • is_tag(tag1, user1, thing_id)
    • is_tag(tag2, user1, thing_id)
    • ...
    • review(user1, thing_id, description, extended, date)
    • ...
  2. review for user "user_x"
    • ?review(user_x, THING_ID, DESC, EXT, DATE)
  3. review for user "user_x" with tag "tag_y"
    • ?review(user_x, THING_ID, DESC, EXT, DATE), is_tag(tag_y, user_x, THING_ID)
We could imagine some better ways to lay out information. This is just a first draft.

Now of course, Prolog does not necessary makes sense for us because:
a) We already have it working in SQL
b) SQL is much more used and should therefore be more tunable, stable, etc.

Still the Prolog way of things is interesting and powerful. We could have written a code with a logic near Prolog instead of our custom code.
Tags:

Wednesday, September 21, 2005

When California Was An Island


This is from an old (1680s) big (2 tons) Coronelli globe, currently displayed in Grand Palais, Paris. Can you spot San Francisco there?

When California Was An Island


This is from an old (1680s) big (2 tons) Coronelli globe, currently displayed in Grand Palais, Paris. Can you spot San Francisco there?

Friday, September 16, 2005

Currying - A Very Interesting Use Of Generics

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.

Tags: ,

Currying - A Very Interesting Use Of Generics

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.

Tags: ,

Tuesday, September 13, 2005

On J2EE Portability Accross Application Servers

Brian Alexander Lee wrote:
"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.

On J2EE Portability Accross Application Servers

Brian Alexander Lee wrote:
"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.

Monday, September 12, 2005

JavaBlogs Weekly Top 10 and Java HTML parsing

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.

You will find concrete code using htmlparser in a more recent post, just follow the link.

Categories: , ,

JavaBlogs Weekly Top 10 and Java HTML parsing

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.

You will find concrete code using htmlparser in a more recent post, just follow the link.

Categories: , ,

Saturday, September 10, 2005

Spam In Blog Comments

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.

Spam In Blog Comments

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.

Friday, September 09, 2005

JavaBlogs Daily Analysis

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.


JavaBlogs Daily Analysis

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.


Wednesday, September 07, 2005

Commons-Beanutils Is Slow

The BeanUtil.popupate(bean,map) can be very handy, but if you care about performance, it is quite slow. I ran a micro benchmark on my machine (centrino 1.8ghz, JDK1.5) and found out that BeanUtils is up to 40x slower than a hand coded solution (where I assign each bean field manually). I was a bit surprised to find such a difference. I suppose there is a big penalty for using reflection and another big one for the BeanUtils abstraction (automatic casting, etc.). I did another test without BeanUtils, using if/else statements vs HashMap.get and found out that the if/else string.equals(...) statements can degrade performance by about 10x. The HashMap appears to be very performant, even with just a few elements in.

In conclusion, if you need more performance, consider hand coding or code generation (using aspectj, or annotations for example) rather than BeanUtils. Actually nowadays, using annotations where you used beanutils probably makes much more sense .

Commons-Beanutils Is Slow

The BeanUtil.popupate(bean,map) can be very handy, but if you care about performance, it is quite slow. I ran a micro benchmark on my machine (centrino 1.8ghz, JDK1.5) and found out that BeanUtils is up to 40x slower than a hand coded solution (where I assign each bean field manually). I was a bit surprised to find such a difference. I suppose there is a big penalty for using reflection and another big one for the BeanUtils abstraction (automatic casting, etc.). I did another test without BeanUtils, using if/else statements vs HashMap.get and found out that the if/else string.equals(...) statements can degrade performance by about 10x. The HashMap appears to be very performant, even with just a few elements in.

In conclusion, if you need more performance, consider hand coding or code generation (using aspectj, or annotations for example) rather than BeanUtils. Actually nowadays, using annotations where you used beanutils probably makes much more sense .

Monday, September 05, 2005

Generate your RSS feed in Java

There are some open source projects that can help you in generating or reading RSS feeds in Java. I found only two libraries a bit mature, other code is often embedded in other open source products (jroller for example):
  • Informa: Does various RSS formats and Atom 0.3. Documentation is better than its alternative, but less focused (has some hibernate helper thingy, some lucene helper, etc.).
  • Sandler: There is no working homepage while I am writing this. But the code is of decent quality, supports Atom 0.3 and RSS 1.0. It is easy to use it. However in reality it is not much more than a wrapper around some XML parser specialized in generating an RSS structure or an Atom structure.
  • Ooops, I forgot another important one, Rome. This RSS/Atom framework with a catchy name is very similar to Informa, has good documentation and good looking code. Under the hood it makes use of jdom.
I personally use dom4j since I only need to generate RSS, and RSS, or Atom are just XML. I don't find it particularly verbose to use dom4j for that, and it is very flexible.

If you need to parse feeds, then those libraries might make sense and save you a bit of time. For generating, I think their main interest is to abstract you from the differences in formats. So if you need to handle different formats, a framework will allow you to do it through only one API, which can be a big time-saver.

Categories: , ,

Generate your RSS feed in Java

There are some open source projects that can help you in generating or reading RSS feeds in Java. I found only two libraries a bit mature, other code is often embedded in other open source products (jroller for example):
  • Informa: Does various RSS formats and Atom 0.3. Documentation is better than its alternative, but less focused (has some hibernate helper thingy, some lucene helper, etc.).
  • Sandler: There is no working homepage while I am writing this. But the code is of decent quality, supports Atom 0.3 and RSS 1.0. It is easy to use it. However in reality it is not much more than a wrapper around some XML parser specialized in generating an RSS structure or an Atom structure.
  • Ooops, I forgot another important one, Rome. This RSS/Atom framework with a catchy name is very similar to Informa, has good documentation and good looking code. Under the hood it makes use of jdom.
I personally use dom4j since I only need to generate RSS, and RSS, or Atom are just XML. I don't find it particularly verbose to use dom4j for that, and it is very flexible.

If you need to parse feeds, then those libraries might make sense and save you a bit of time. For generating, I think their main interest is to abstract you from the differences in formats. So if you need to handle different formats, a framework will allow you to do it through only one API, which can be a big time-saver.

Categories: , ,

Thursday, September 01, 2005

The Evil Port 80

I was writing an Atom feed generator for my current project. I chosed to support Atom 1.0 since it looks like it has the capabilities to establish as the next standard. Unfortunately I quickly saw that it was quite hard to test it in the real world (out of the good feedvalidator), as almost nobody seems to accept Atom 1.0 feeds yet, even if it is rapidely changing (there is support for it in Firefox CVS version).

So I decided to support RSS as well, the big question was: which RSS version? After grabbing lots of info on the subject, I opted for 1.0 again (more flexible, more different than Atom). It was actually quick to support RSS, but then when in real world, neither Google Desktop nor My Yahoo was willing to accept my feed. I looked at every bit of my xml, fiddled with Tomcat configuration in any possible way when I saw that no request was coming to my server from Yahoo or Google. And finally I thought, hmm maybe it's the port. I restarted my server on port 80, and yup, it worked!



I wonder why Google Desktop and My Yahoo don't support another port than port 80 for RSS feeds.

tags: Categories: , , ,

The Evil Port 80

I was writing an Atom feed generator for my current project. I chosed to support Atom 1.0 since it looks like it has the capabilities to establish as the next standard. Unfortunately I quickly saw that it was quite hard to test it in the real world (out of the good feedvalidator), as almost nobody seems to accept Atom 1.0 feeds yet, even if it is rapidely changing (there is support for it in Firefox CVS version).

So I decided to support RSS as well, the big question was: which RSS version? After grabbing lots of info on the subject, I opted for 1.0 again (more flexible, more different than Atom). It was actually quick to support RSS, but then when in real world, neither Google Desktop nor My Yahoo was willing to accept my feed. I looked at every bit of my xml, fiddled with Tomcat configuration in any possible way when I saw that no request was coming to my server from Yahoo or Google. And finally I thought, hmm maybe it's the port. I restarted my server on port 80, and yup, it worked!



I wonder why Google Desktop and My Yahoo don't support another port than port 80 for RSS feeds.

tags: Categories: , , ,