Thursday, September 29, 2005
Interesting Plug-In Framework - DPML Transit
I have not heard of DPML before, they seem to write useful software. Has anybody used those frameworks already?
Tags: java, framework, programming
Interesting Plug-In Framework - DPML Transit
I have not heard of DPML before, they seem to write useful software. Has anybody used those frameworks already?
Tags: java, framework, programming
Wednesday, September 28, 2005
Java Puzzlers - Can you figure this out?
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, book, review
Java Puzzlers - Can you figure this out?
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, book, review
Monday, September 26, 2005
Is Prolog Better Suited Than SQL?
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 ...:
- let's define some facts:
- is_tag(tag1, user1, thing_id)
- is_tag(tag2, user1, thing_id)
- ...
- review(user1, thing_id, description, extended, date)
- ...
- review for user "user_x"
- ?review(user_x, THING_ID, DESC, EXT, DATE)
- 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)
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: book review
Is Prolog Better Suited Than SQL?
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 ...:
- let's define some facts:
- is_tag(tag1, user1, thing_id)
- is_tag(tag2, user1, thing_id)
- ...
- review(user1, thing_id, description, extended, date)
- ...
- review for user "user_x"
- ?review(user_x, THING_ID, DESC, EXT, DATE)
- 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)
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: book review
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
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: java, programming
Currying - A Very Interesting Use Of Generics
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: java, programming
Tuesday, September 13, 2005
On J2EE Portability Accross Application Servers
"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
"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 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, rss3, java
JavaBlogs Weekly Top 10 and Java HTML parsing
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, rss3, java
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
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
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
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
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
- 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.
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: java, rss, atom
Generate your RSS feed in Java
- 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.
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: java, rss, atom
Thursday, September 01, 2005
The Evil Port 80
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: atom, rss, gdesktop, syndication
The Evil Port 80
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: atom, rss, gdesktop, syndication