Garbage Burrito!

an internet web blog by Ben Kittrell

This is what drives me crazy about Java

This is what drives me crazy about Java
Ben Kittrell - 12/20/2006 14:59:00
Comments: 1
Last Comment: 01/04/2007 09:07:19

I found this in some code today. 

    private static final String ASCENDING = "ascending";
    private static final String DESCENDING = "descending";

WHY!?!?!?!?!?!?!?!!

Don't get me wrong, constants are good, but that's just stupid.  I talked to my cube-mate Nandhu about it, and at first he said it was to save memory, but that's not true because there will only every be one "ascending" no matter if it's final or not.

We talked about how they can be good if you anticipate it changing, or if it's some sort of flag.  The only positive factor we agreed upon for this instance was that it saves you from spelling errors, cause the constant is checked at compile time.  That's weak IMO.

I guess it's not so much what drives me crazy about Java, but rather Java Developers.  Everything must be abstracted as much as possible.  I'm surprised they didn't put it into a super class, just in case other classes need it.  Or maybe it should be in the service layer behind some EJB's.   

Mmm, symbols make me happy.

Comments: 1
Last Comment: 01/04/2007 09:07:19

Comments

1. simon   |   01/04/2007 09:07:19

Actually I reckon that the compile-time spell checking is actually a pretty good reason to do it. That and refactoring support.

I'm no Java development apologist, though -- I hate the layers of crap that a lot of Java projects end up in (although I've been involved in ones that didn't). If there were some syntactic sugar to make that look less lame, I'd use it. But one of the things that annoys me most about Ruby and other dynamic languages is that there's no ability to do simple spell checking, and pretty bad chances for refactoring support.

That code you've outlined there is certainly the best way to do it in Java as it stands now. The other options are nowhere near as good: put string constants throughout your code (urgh) or use an int or something (also urgh). In C# you could use an enum, which might improve things a little, but would still be reasonably urgh.

Post a Comment


Are you human? Please enter the word below.
M2n1cnnllmpwzzeyodqxntywmzu=


powered by Doodlekit™ Free Website Builder by Doodlebit™ Website Company