This Week in Java

by Robert Cooper

I have been kind of lax in posting some of these things, but there are some moderately interesting whippings of the dead horse this week.

Gosling had a sitdown with JDJ where he discussed the nature of Ruby and PHP. That, of course, smells of nerd holy war. Assaf takes him to task on his characterization of Ruby and PHP as single-purpose languages, Hansson says that versatility is overrated anyway, Artima dubs the whole thing moot but has a good discussion.

Also at Artima, a paper that explains that code generation is back, and it's baaaad. It is a well written paper, but this kind of goes to the Model Driven Dev model which I have espoused for a while. I know code generation still gets a bit of a bad rap. HOWEVER, the author does miss that Hibernate, in fact, IS a code generator. It works by generating subclasses of your pojos to handle the mapping. What it does lack, however, is that first step as well as a more reasonable "convention over configuration" attitude.

The Great Web Framework Survey continues with RIFE. I have glanced at RIFE in the past, and it seems like a good system. It is very much a RAILS system with more of what I would call a "Java Flavor" -- it is done like you do things in Java rather than trying to copy something else. I REALLY don't like the fact that it has its own Velocity-style templating system. Why can't use JSP/JSTL and some custom taglibs still escapes me. Of course, why JSP doesn't have something equiv to RIFE's ${v WEBAPP:ROOTURL/} is beyond me too :P.

(SP corrected. Thanks!)

15 Comments

tej prakash
2006-03-17 10:43:19
i m not eligible to send any java script data.
Trevor
2006-03-17 14:01:55
That's "Gosling", not "Gossling".
Trevor
2006-03-17 14:02:54
"in face"?
Trevor
2006-03-17 14:03:36
"it's own" --> "its own"
cooper
2006-03-17 14:06:53
Yeah, OK... That's what I get for trying to do that too fast. Funny the Google spell check didn't catch Gossling.
Aristotle Pagaltzis
2006-03-18 00:14:10
Best response to Gosling was Ryan Tomayko's Gosling Didn't Get The Memo which got republished at SYS-CON too.
Alexandre Poitras
2006-03-18 08:13:04
I think your code generator definition is way too large. A code generator is usually something that add code in your source file or new files to your project before executing it. Hence, the generated code is visible to the developers.


Hibernate generates runtime proxies to decorate your classes. You could do the same with an AOP engine. Of course, AOP generates new bytecode because isn't part of the Java language...

cooper
2006-03-18 10:36:40
A code generator is usually something that add code in your source file or new files to your project before executing it.


Hibernate generates runtime proxies to decorate your classes. You could do the same with an AOP engine.


I think that is a fair definition in this context, but you have to look at point that opens the Artima article:

In an article introducing Ruby on Rails' Active Record, Bruce Tate suggests that Java could enjoy some of the benefits of Rails by taking a wrapping rather than a mapping approach to persistence. I think this misses the point. What Rails really demonstrates is the benefit of code generation.

Active Record (and by derivation RoR) is *itself* a code generator too. However, it is doing it under the guise of the dynamic nature of the Ruby language, so it is also hidden from the programmer.


My point was, Hibernate is really not so different, except for its mapping layer which is used to generate said code. This, however, is an element of AR/RoR's "Convention over configuration" ideology rather than something implicitly different about the means of accomplishing their O-R mapping.

assaf
2006-03-19 01:53:06
Code generation works great until you hit some soft spot, and then ... in some projects I spent more time working around generated code than it saved me to begin with. I don't like mapping files, but I prefer them.


I think the Artima article was wrong in stating that Rails uses code generation. Rails dynamically augments your classes, avoiding all the traps of code generators.


One thing Java could learn is how to extend code without generating anything.

Alexandre Poitras
2006-03-19 08:07:40
Ok, I see your point now. Thank for the clarification then :)



2006-03-19 08:10:15

One thing Java could learn is how to extend code without generating anything.


AOP is precisely adressing this issue. Ruby can use its dyanmic nature but Java can rely on AOP to do it. I just wish AspectJ was made part of the core language.

Alexandre Poitras
2006-03-19 08:15:13

My point was, Hibernate is really not so different, except for its mapping layer which is used to generate said code. This, however, is an element of AR/RoR's "Convention over configuration" ideology rather than something implicitly different about the means of accomplishing their O-R mapping.

I think the philosophy, having default conventions wich can be overriden if they aren't good enough, is slowly reaching the Java World. Open source projects like Maven 2 and Struts Shale already adhere strongly to this philosophy. In my mind, it would be the best contribution of RoR to the Java world, well I hope so :)
cooper
2006-03-19 21:36:58
I think the Artima article was wrong in stating that Rails uses code generation. Rails dynamically augments your classes, avoiding all the traps of code generators.


One thing Java could learn is how to extend code without generating anything.


Well, and I have been yelling to the hills or anyone who will listen that if the Java Dynamic Proxy system would let you create a proxy of any object -- basically have every concrete object create a MyFoo.class.getInterface() -- you would get 90% of the way there, without adding a bunch of dynamic language features to Java.


This is, in essence, what everyone -- Hibernate included -- uses CGLIB for anyway.

assaf
2006-03-20 01:59:33
AOP does extend code without being a code generator, and you get visibility into the source code used for extension.


From what I read it extends existing methods. Can AOP create a new method to act as default if an existing method does not already exist?

Alexandre Poitras
2006-03-20 12:44:06

From what I read it extends existing methods. Can AOP create a new method to act as default if an existing method does not already exist?

Yup, AOP most powerful feature is to create mixin. It is called an introduction advice.