Quote Of The Day
I didn't know this.
Tom Tromey: "Software engineering" is the endless renaming of existing ideas, and the history of it is largely the story of IBM introducing the same ideas that it likes, over and over, with different names each time, until they finally take hold.
John Vlissides
Richard Gabriel: John Vlissides passed away on Thursday, November 24, 2005, after a lengthy illness.
I Like My Checked Exceptions Just Fine!
It's not as bad as they would have you believe.
Eric Burke made headline at TheServerSide.com with his explanation about why unchecked exceptions are better.
While I agree that Hibernate 2 probably abused checked exceptions and that Hibernate 3 is probably right in switching to unchecked exceptions, I don't believe you can blame it all on checked exceptions. The trouble with checked exception abuse has more to do with abuse than with checked exceptions.
For the record, let me just say I like my checked exceptions just fine.
I like it when my compiler compels me to think about exception handling when I call certain methods. The authors of the methods thought it important enough to alert me, the user, to make the exception checked. As a consequence I am aware of the possibility that the exception might be thrown at that spot and can choose to either handle it or propagate it. The burden of exception propagation is the price we pay for the checked exception facility in the Java compiler.
Not all exceptions are implementation details. SQLException in JDBC, for example, is part of the JDBC specification. Client code that handles or propagates SQLException are perfectly portable among different JDBC drivers. In Eric's example, HibernateException bleeds through because Hibernate chose to not use a standard Java exception class. Again, the ill lies in the fact that Hibernate uses a totally proprietary API, not that Hibernate uses checked exceptions. Plus, are we ever going to handle any Hibernate exceptions in our code, checked or unchecked? The moment we do, we just married our code to Hibernate. Having our code married to Hibernate is the price we pay for using the Hibernate library.
As for the boilerplate code that Eric alluded to, which in the most general case looks something like this:
try {
// do some lower tier thing
} catch (LowerTierCriedException e1) {
throw new ThisTierCriedException(e1);
} catch (LowerTierSmiledException e2) {
throw new ThisTierSmiledException(e2);
} catch (LowerTierYawnedException e3) {
throw new ThisTierYawnedException(e3);
}
my question is "Why?" If the answer is "I just don't want the tier above me to see any exceptions thrown by the tier below me," which is a legitimate reason for doing such things, then you have to do the wrapping regardless of the checked-ness of the exception. Otherwise the upper tier would still see the unchecked exceptions. The boilerplate code is the price we pay for cleanly separated tiers in the application architecture.
If the answer is "I don't mind lower tier exceptions bleeding through me to upper tiers. I just hate to declare these exceptions in my method signatures. I'm ready for these exceptions bubble up the stack frame and potentially kill my thread." That's a sign of lower tier checked exception abuse.
Another benefit of checked exceptions is the conceptual clarity it offered: checked exceptions are problems the client code must handle, unchecked exceptions are usually programming errors.
From a practical point of view, the use of checked exceptions has its place. We developed in Java for 10 years with checked exceptions. The JDK itself has hundred of checked exceptions. All sorts of applications were written, from small dozen-user web tools to huge popular Java based websites to high-throughput transactional servers, all while taking advantage of checked exceptions.
While googling on this subject today, I realized that my point of view might not be popular. Many smart people have spoken out against checked exceptions. Then again, I might also be in pretty good company.
Oh, BTW, I learned a new phrase while clicking on the various links today: syntactic salt—The opposite of syntactic sugar, a feature designed to make it harder to write bad code. The Wikipedia paragraph on checked exceptions classified Java's implementation of checked exception as syntactic salt.
Now that we've got the checked exceptions stuff out of the way, we can start some real discussion—"I'm going to build a bike shed, what color do you think is best?"
Hackers Cracked Gmail
It's time for the Gxcitement to die down a bit.
I usually get flooded with blog entries about anything that happens at Google. But somehow I missed this one by several days:
RED HERRING | Hackers Cracked Gmail: Google fixed a problem in its email program that allowed hackers to read people’s email and pose as legitimate users.
...
Google didn’t make a public announcement about the problem. Companies such as Microsoft typically alert their users to security flaws in their software.
Intel Contributes To Apache Harmony
Mikhail Y Loenko: With pleasure I announce the first contribution to Harmony on behalf of Intel. The archive with the contribution is uploaded to the following location: http://issues.apache.org/jira/browse/HARMONY-16
PostgreSQL 8.1.0 Comes To Cygwin
It works again.
For the longest time, my development relational database of choice has been PostgreSQL. It offers the features that I care about (the simple stuff: create table, select from where order by group by, transactions, JDBC drivers) on the platforms that I use the most often (GNU/Linux, Windows/Cygwin) under a BSD license.
What I like the most is the fact that it comes with the Red Hat distribution since the early days. For the last few years, a Cygwin compiled version also showed up as part of the Cygwin net distribution.
The Cygwin version, however, was broken earlier this summer. And I was without a database on Windows for a while. Finally last week, Reini Urban announced the availability of PostgreSQL 8.0.4 and 8.1.0 for Cygwin.
Setting up PostgreSQL as a Windows service has always been a tricky endeavor. The new release offers some relief by providing an init script that can simplify the process. According to the release notes, it could be as simple as:
/etc/rc.d/init.d/postgresql initdb /etc/rc.d/init.d/postgresql install /etc/rc.d/init.d/postgresql start
While this is essentially true, there are some hurdles that I have to jump over to have everything up and running. Let me just say that the script can be improved upon. Here's my Cygwin PostgreSQL 8.1.0 setup first impression:
- First of all, the CYGWIN environment variable needs to contain the word server. (I have CYGWIN=ntsec server.)
- The cygserver service needs to be installed already. (Running cygserver-config once will do it.)
- The initdb task will create the database template in /usr/share/postgresql/data and create a directory /tmp/postgresql for runtime use.
- After a fresh installation, the directory /usr/share/postgresql already contains some files and subdirectories. initdb won't like it if /usr/share/postgresql/data already exists and is non-empty or if /tmp/postgresql exists. (A failed run of initdb will create such a situation.)
- There are plenty of file/directory permission problems that would cause the install or the start steps to fail. All because the service is run as Local System, not the logged in user. Files and directories that need to open up permission include
- /usr/sbin/postgres.exe (needs chmod ugo+rx),
- /usr/share/postgresql/data (needs chmod ugo+rx),
- /tmp/postgresql (needs chmod ugo+rwx),
- /usr/share/postgresql/data/global (needs chmod ug+rwx.)
- The /etc/rc.d/init.d/postgresql script contains a chunk of code to ensure that the CYGWIN environment variable contains the word server. But it went too far. This caused the install task to fail with an error message saying "CYGWIN must contain server" even though my CYGWIN already does.
- The log file at /var/log/postgresql.log provided valuable information while I'm trouble shooting my setup.
- The psql (PostgreSQL's interactive SQL command line tool) seems to look for a UNIX domain socket to connect to at the wrong place (/tmp/.s.PGSQL.5432 instead of /tmp/postgresql/.s.PGSQL.5432.) I have to connect to the TCP socket by running psql -h localhost.
- The bootstrap user Id for PostgreSQL is SYSTEM. So to add my own login to PostgreSQL I need to run /usr/sbin/createuser -U SYSTEM
Here's the portion of /etc/rc.d/init.d/postgresql I modified
# check for CYGWIN containing server
if ! echo $CYGWIN | grep -q server
then
echo "ERROR CYGWIN must contain server for cygserver to work properly"
exit 1
fi
The if line used to say
if [ -n "${CYGWIN%server}" ]
It sounds like a lot written down, but the actual trial and error of the setup is pretty easy and It took me less then 30 minutes to figure all of these out. What is important is that at the end, I have a functional PostgreSQL server running as a Windows service again:
[weiqi@gao] $ psql -h localhost
Welcome to psql 8.1.0, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
weiqi=# create table people (first_name varchar, last_name varchar);
CREATE TABLE
weiqi=# insert into people values ('Weiqi', 'Gao');
INSERT 0 1
weiqi=# select * from people;
first_name | last_name
------------+-----------
Weiqi | Gao
(1 row)
weiqi=# \q
[weiqi@gao] $
Having DSL Problems
I'm having DSL problems. My ISP suspects the modem is the cuprit and will send a replacement one by UPS. It'll be a couple of days before it arrives. I have reverted back to dial-up for now.
%!@~~4.18b:~~!*###34BIT95y LOGIN:PASSWORD:LOGIN:PASSWORD:LOGIN:PASSWORD ATR0D6XRINGINGING;;; NO CARRIER...
EJB 3.0 At The JUG
I like what I hear.
Yesterday's EJB 3.0 talk at the St. Louis Java Users Group is another one of the more livelier presentations, with a lot of audience interactions.
Raj Patel from Harpoon Technologies began the talk with "I've done a lot of Hibernate work, but I've never done any EJB 2.1s. Those who did probably know how painful it was. EJB 3.0 is going to change that."
Having not read the EJB 3.0 specs myself (I'm waiting for the final version), I liked what I heard. I have seen earlier EJB 3.0 introductions on Java.net and elsewhere, but none of them registered. Again the open Eclipse project with live code helped.
The overwhelming impression I got from yesterday:
- EJB 3.0 is very close to Hibernate
- EJB 3.0 annotations are orders of magnitudes simpler than EJB 2.1 deployment descriptors
- The EJB 2.1 concepts (stateless session beans, stateful session beans, entity beans, message driven beans, activation, passivation, declarative transaction management, declarative security management) all carry over to EJB 3.0. It's the syntax that is simplified
- EJB 3.0 does dependency injection with annotations
- EJB 3.0 does bean level method invocation interception (AOP) with annotations
- EJBQL is similar to HQL (Hibernate query language)
Other observations:
- Hibernate will evolve and be a superset of of EJB 3.0 [Update: See Eric Burke's correction]
- EJB 3.0 offers some features that shadow the Spring Framework, but not enough to replace it
- The embeddable JBoss EJB 3.0 container is cool
- Raj says JDO is dead, JDO vendors are going EJB 3.0 (Solarmetric is bought by BEA.)
I guess a more pressing question is this: "Should I adopt EJB 3.0?"
And I think the answer is "It depends." If you've been following the open source developments pretty closely and are using Spring and Hibernate, there is no need to hurry. If you've stuck with the party line and are still doing EJB 2.1 or even 2.0, EJB 3.0 will look very attractive.
The Podcast You Can't Afford To Miss
SICP, taught by Abelson himself, is available for free
There are two kinds of programmers: ones who have read SICP, and ones who haven't.
Those who have often smile in secret knowledge that they know better when they hear those who haven't going on and on about "object-orientation," "design patterns," "meta-programming," "closures," and "continuations" as if they are magic.
For those who haven't clicked on the link, SICP stands for Structure and Interpretation of Computer Programs, by Harold Abelson and Gerald Jay Sussman, an introduction to computer science textbook in use since 1981. Here's praise of this book from the guy who wrote the original Mozilla (aka Netscape Navigator):
Jamie Zawinski: If you don't know C++ and want to learn what this whole 'object oriented programming' thing is all about, there is one and only one book you should read first, and that is "Structure and Interpretation of Computer Programs", by Abelson and Sussman.
Now the good news. Professor Abelson has made available, free under the creative commons license, a complete presentation of the course, given in 1986 for Hewlett-Packard employees.
Now the better news. The lectures, twenty downloads averaging 1.5GB each for a total of almost 22 hours, is also available as a podcast at this URL: http://feeds.feedburner.com/SICP. Thanks to Max Khesin.
IBM Contributes To Open Source Java Project
Tim Ellison: I'm delighted to be able to make a code contribution to the Harmony project on behalf of IBM.
Dalibor Topic: The fun's just starting.
Harmony, as you know, is the free Java project at Apache. The IBM contribution can be found here.
Cool Program: w3m
It supports tabbed browsing.
Sometimes you just have to stop and take a look around your file system. If you are like me, you'll have a Linux system or a cygwin system with everything installed.
And one place to look at is /usr/bin. A game I play when I was bored is to try to memorize what each executable there does. Once in a while, a new program comes along and I go "what does that do?"
That's how I discovered w3m a while ago. It comes with the net install of cygwin. It's a text-based web browser in the tradition of Lynx and links. It got my attention when I right clicked on a link in it. A context menu, of course text-based, popped up. And one of the menu items is the "Open in new Tab." "Nice!" I remember saying to myself.
Well, I've been using it ever since. It's especially handy for such things as README.html files, where a
[weiqi@gao] $ w3m README.html
command will open the file right there, just like
[weiqi@gao] $ less README
had the file been a plain ASCII file.
Here it is in action, with four tabs open:
Java News Brief (JNB): Create Proxies Dynamically Using CGLIB Library
Jason Zhicheng Li wrote this month's Java News Brief (JNB) article: Create Proxies Dynamically Using CGLIB Library:
Jason Zhicheng Li: Essentially, CGLIB dynamically generates a subclass to override the non-final methods of the proxied class. It is faster than the JDK dynamic proxy approach, which uses Java reflection.
He also published the Roll your own AOP article on Java.net yesterday.
Weblog As PR
They shall know you by your weblogs.
Talking with my coworkers about the year-end review yesterday at the office, I mentioned that I've put "consider using weblogs as a communication tool, both internally and externally" as a suggestion for improving communications. And Jonathan and Dan went "Huh?"
As if they know what I'm looking for, both Simon Brown and Cathy Sierra blogged on related issues in recent days:
Simon Brown: ... a few suggestions really shout out to me as being spot on.
- Instead of print ads, get some training articles out there: This is something that I'm a big fan of and it's part of our culture at Evolution. It's down to thought-leadership, although rather than *tell* somebody we're good, we *show* them. ;-)
- Instead of hiring a PR agent, get blogs for employees and/or users: This is a great idea and, provided you have satisfied and enthusiastic employees/users, you're on to a winner here since promotion will come from within. If you don't, at least you'll realise that you need to fix some stuff!
- Instead of spreading compelling yet fake stories, tell the real story and make sure it's good: Kind of ties back nicely to the previous point, but if you don't have a good story internally, how do you expect to promote that externally?
Cathy Sierra: I've worked for companies that spent their entire ad and marketing budget on making their existing users deliriously happy. Let's say your marketing and/or ad budget doesn't have the same legs it used to, or that you've just decided to make a change. Or maybe you don't even have a marketing budget. Is there something you can do that might be more creative and, in many cases today, at least--if not more--effective?
These are off the top of my head and my usual disclaimers apply (doesn't work for everything, etc.), and I hope others will add better ideas.
Cathy's list is rather long to be quoted here, but it's worth a read. Go ahead and read the whole thing.
It is interesting to note that OCI has been putting out training articles for years in the form of our Java News Brief (JNB) and CORBA Articles series.
It's hard work. But it can be done.
