[jdom-interest] More changes

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Jul 19 09:39:31 PDT 2000

At 10:35 AM -0500 7/19/00, Brett McLaughlin wrote:

>* What do people think about removing the convenience methods (like
>getIntContent()) on Element.java? Mark Diekhans pointed out that getting
>a default value from an attribute is quite different from getting one
>from an Element - typically, it means the Element is optional, or not
>there, but we also return the default if the /format/ is incorrect.  For
>This currently returns 80, and should really result in an error - it
>masks problems in the underlying XML, which is generally a bad thing, I
>think. It is very hard to track this down, and different programs using
>different defaults can really obfuscate the document. So I'm actually
>for removing all the getXXXContent methods (but only on Element.java,
>not Attribute.java, where they make more sense).

I agree, but for different reasons:

I've come to believe these methods are unimportant syntactic sugar, 
that add complexity to the API while providing no real benefit to 
most programmers. The smaller JDOM is, the  simpler and easier it is 
to learn and document. 80+ methods in a class simply looks too 
intimidating even if you can ignore most of them most of the time. 
I'd simply rather have fewer methods in the class.

I do see your point about the problem with returning the default 
where the format is incorrect. However, I'm not sure why this 
reasoning applies to Element and not to Attribute. After all, 
wouldn't we have exactly the same set of problems with <connection 
port="y80"/>?  Perhaps we should remove the overloaded methods that 
provide a default value from Attribute?  Or perhaps they should only 
return the default value if the attribute is missing but throw a 
NumberFormatException if the format is in error.

| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |

More information about the jdom-interest mailing list