Defending UnsupportedOperationException
I just listened to super-smart guy
Elliot Rusty Harold critique the Java Collections API on his recent
Javapolis interview:
In the Java Collections API, I really do not like the UnsupportedOperationsExceptions. I do not like that given a list I don't know whether I can actually add something to this list or not. I don't know how it behaves by virtue of it's being a list. I don't know whether the methods it advertises actually work or don't. That bothers me a lot.
I think that UnsupportedOperationExceptions are a reasonable solution to a difficult problem. The
Java Collections API Design FAQ describes in detail why UnsupportedOperationException is the lesser of two evils.
I'm not sure why Mr. Harold is so offended by UnsupportedOperationException - just like NullPointerException, all occurences of it should be found and fixed during testing. I love using UnsupportedOperationException in my code! Frequently I'll extend the
Format
class, which is intended to convert objects to Strings and back. It has two abstract methods:
format(...)
to convert objects to Strings, and
parseObject(...)
to convert Strings to objects. When I don't need parsing, I can simply throw UnsupportedOperationException() from the
parseObject()
method.
# posted by Jesse Wilson
on Wednesday, April 19, 2006
0 comments
post a comment
An IntelliJ live template for Swing developers
Whenever I'm prototyping Swing code, there's lots to remember about getting a component on screen:
invokeLater() for thread safety
setDefaultCloseOperation() to clean up after myself
pack() and setLocationRelativeTo() for a convenient frame
To make this easier, I've created a Live Template for IDEA. Add this to your collection of live templates, then simply type swing[tab]
and remove a little more boilerplate from your life!
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { public void run() {
JPanel panel = new JPanel(new BorderLayout());
$FOCUS$
JFrame frame = new JFrame();
frame.getContentPane().add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}});
}
# posted by Jesse Wilson
on Tuesday, April 18, 2006
2 comments
post a comment
James' Screencasts in the IDEA Blog
Today's IntelliJ blog makes
mention of the Glazed Lists screencasts, and how they use IntelliJ. Fantastic! Some lovin' from our Swing-commanding friends at
JetBrains is always welcome.
We're gearing down towards a new Glazed Lists rev, with a whole bunch of new functionality and the bugs that come with it. I'm frustrated 'cause I don't have a massive project staring me in the face with interesting problems for Glazed Lists to solve! Perhaps if I'm not doing Swing work at El Goog, I'll dig in and start a rich client project!
In other news, publicobject.com has a refresh. It's currently ultra simple - but I've got ideas and this is my starting point!
# posted by Jesse Wilson
on Monday, April 17, 2006
1 comments
post a comment