For the 2nd session of the day, I've decided to attend the session on AOP. My choices were Converting
XML (Ben Galbraith), JSF (David Geary), What's new in EJB 2.1 (Monson-Haefel) and Runtime Code
Generation (Glenn Vanderburg). I asked David about his JSF presentation and he said it was "boring" so
I decided to skip it. This session, in the first 10 minutes, is pretty boring too. I might have to duck
out of this and attend another session - but none of the other sessions really interest me. This
one started this morning, and it seems to be a continuation of this morning session. It's mostly
on AspectJ and he's doing the good ol' logging example. I don't really have an interest in using
AspectJ since Spring's AOP is more than adequate for my needs. Oh well, I guess I'll stick around and
relax.
Ramnivas is using Eclipse to compile his aspects, and shows us how if he uses "javac" to compile everything,
no aspects are added. I'm guessing that there's some sort of plugin for Eclipse that allows for easy
compiling of aspects. A new feature in AspectJ 1.2 is the ability to set an ASPECTPATH and then use "aj"
rather than "java" to run code. This achieves the same effect as compiling the aspects in Eclipse. The "aj"
script appears to just set the system classloader.
Now Ramnivas is showing us how you can use an aspect to define pointcuts on internal appserver classes. His
example involves WebLogic, the J2EE Petstore and logging any EJB method calls. To use this, he has to
start WebLogic with a custom script, that has a custom classloader defined. For some reason, we're now talking
about log.debug()
vs. if (log.isDebugEnabled()) { log.debug() }
. Ramnivas
thinks that most folks don't wrap their debug statements (the proper way). Who doesn't know about this?! I'd
like to think that most developers are writing the 3-line version vs. the 1-line version.
An interesting quote: "So many things to show you - 3 hours is not enough." Maybe if we didn't have to
wait 2 minutes for WebLogic to start each time, 3 hours would be plenty. ;-) Ramnivas just added
logging to all the classes in the blueprints packages and then reloaded the page. There looks to be several
thousand method calls occurring behind the scenes for a simple page. Of course, there's lots of tag libraries - but
still - PetStore is a ridiculously complex application. Why did some ever impose this crap upon us as "best
practices" for Java. IMO, best practices should be based around simplicity, maintainability, testability and
performance. Does the PetStore even ship with unit tests? I'll bet it doesn't...
Now we're watching a pretty cool demo where Ramnivas is using aspects to enforce coding policies. In this
example, he's using aspects to enforce rules in EJBs (i.e. no static variables, swing or threads). It interesting
in that the aspects actually prevent compilation and display errors defined in the aspect. It's a neat idea, but
I'm suspicious in that a lot of this AspectJ stuff seems to be Eclipse-specific. What I mean by this is that
Eclipse seems to be required for compilation. Is it easy to aspect-enhance your classes using Ant? I would
hope so.
Ramnivas seems to be quite the AspectJ expert. He mentioned that he wrote a book for Manning and has mentioned
a couple of his contributions to AspectJ in this presentation. I admire authors that write and contribute to projects
at the same time. It's often an indicator that the person knows what the hell they're talking about.
This afternoon's first session choices are as follows: JSF Advanced Topics (Geary), Intro to J2EE Web
Services (Monson-Haefel), JSR166 (Glenn Vanderburg), Rhythm (Brian Boelsterli) and GUI Development (Ben
Galbraith). Web Services and Rhythm are 3 hour presentations, so I might stay away from those - that's just
too long for me. Now that I'm sitting in the 2nd half of a 3 hour presentation - it seems that these sessions
are best attended in the first half. It's almost as if the presenter is trying to find things to talk about
in the second half. Or maybe AOP is just a boring-ass topic. ;-)
I'd like to go to Brian's talk on Rhythm, since he's a good friend and mentor of mine. But then again, I
learned Rhythm from him - and use it daily - so I don't know that I'd get anything out of it. Advanced JSF
looks good, maybe I'll go to that one. For the 2nd session this afternoon, I'll probably attend Howard's
Creating Powerful Web Forms with Tapestry. Maybe I should stick with JSF and Tapestry and
make it a web-intensive afternoon. Both presentations are even in the same room!
Groovy makes for easier for
loops. As an example,
for (Iterator i = r.iterator(); i.hasNext();) {
System.out.println(i.next());
}
... becomes ...
for (i in r) {
System.out.println(i)
}
With Groovy, you can remove semi-colons and use dynamic typing. This means you can basically remove
any types (i.e. List). The nice thing is that typing is a choice - you can use static typing like
you do in Java write now.
One thing I forgot to mention about this conference. Jay Zimmerman (the organizer) has a pretty good
idea. The full schedule is printed on the back of the conference badges attendees hang around their
necks. This makes it very easy to find and decide what session to attend. I wish more conferences
would do this.
Richard is going through closures, native list looping and how you can remove classes and method
declarations. It seems to me that one of the coolest features of groovy is that all of the
shortcuts are optional. This is huge IMO, because it means the developer has a choice -
which is always nice. Richard says that in his experience, a program written in Groovy is about
1/5 the size of the same thing written in Java (an 80% reduction in code). Someone in the room asked
about performance. I was surprised to hear Richard say that Groovy was a bit slower. After asking
about this, it turns out that Groovy can be executed as a script or as native bytecode (if compiled
first). So when Richard said "it's slower" - he meant the script version is slower - because
it's interpreted - just like any scripting language.
Sweet - I just got a connection on the hotel's wireless network. I was in the midst of
reading some RSS feeds in NetNewsWire and noticed
a JRoller blog with additional coverage of this conference. ... Sorry, I got sidetracked for the last 20 minutes with the Spring developer's mailing list - talking
about simplifying Spring
forms in JSPs.
Back to Groovy. Richard, and several members of the audience, are talking about closures. I still
don't really get what they are and why they're important. I guess I shoulda been paying attention. ;-)
Groovy has regular expressions built-in - based on JDK 1.4 Regex. In Groovy, == is the same as .equals()
in Java. And === is equal to == in Java. Apparently, they did this because folks usually use ==
when they really want to get the functionality of .equals(). I like the idea that == in Groovy means
the same thing as == in JavaScript, but I don't know how I feel about ===. I'm guessing that using
.equals() is still possible.
Richard has a good presentation style. He does a lot of coding during his presentation - writing
scripting, compiling and executing them. Unfortunately, since I got internet access, I haven't been
paying attention as much as I should - but at least 75% of the class seems to be extremely engaged. An
interesting thing about this conference vs. the MySQL Conference in Orlando. At MySQL, almost all the
presenters had PC Laptops. In fact, I was one of the only ones with a PowerBook. At this conference,
Bruce Tate is the first one I've seen that uses a PC. Almost all the presenters are using PowerBooks -
mostly 15".
Groovy can be used for easily writing XML as well as enhancing your Ant build scripts. One thing
I'm hearing at this conference, as well as seeing on blogs recently is that AppFuse's build.xml could
probably use some refactoring. With Ant's new import feature and the ability to write scripts in
build.xml - it's likely it could be greatly simplified. Then again, it ain't broke - so why should
I fix it?
Richard's showing us how easy it is to write XML using Groovy's shell:
import groovy.xml.*;
x = new MarkupBuilder();
a = x.Envelope { Body("Hi")}
If you run this, you'll get:
<Envelope>
<Body>Hi</Body>
</Envelope>
An interesting thing from the above demo. When Richard added "print a" as the last line in the
script, it printed "Envelope" after the XML output. He said this is because the last line in Groovy
is treated as the script output. That's kinda wierd IMO. GroovySQL - pretty cool and simplistic. A
nice feature is that connections are automatically closed (when the script completes). Another thing
Richard mentioned is that Files are also automatically closed - even when used inside an Iterator. It
seems to me that Groovy is trying to stop many newbie Java developer mistakes, as well as do more
automatic resource management (closing files and connection). This is actually similar to Spring in
how its JDBC and ORM support manages closing connections behind the scenes. Good stuff - another tool
to make life easier for Java Developers.