[jdom-interest] Thoughts on...

Paul Jakubik pauljakubik at yahoo.com
Thu Mar 15 11:42:31 PST 2001


When it comes to APIs more is not always better. It is
a balancing act between convenience on the one hand,
and ease of learning and maintenance on the other. If
anything, I'd say that JDOM has already gone further
to the side of providing convenience than it should
(but of course anytime you are balancing competing
forces it often comes down to matters of taste and
everyone's is different).

In this case I think it is clear that there is no need
to add these extra methods. Not only is there a
concise solution in the language ("" + var), but in
the example you gave you would be better served by
saying something like ("mystring" + var). Your code
would be more concise and, for my taste, clearer.

I vote against providing these convenience functions
since string formatting is not JDOM's job and since
there are alternatives that aren't as wordy as what
you used in your examples. If you really want
something better, make a string formatting library as
something separate from JDOM.

--Paul


--- Gary Bentley <gb at opengroup.org> wrote:
> I would only want that the addContent would (under
> the hood) makes those
> calls...since JDOM is supposed to be Java oriented
> then it would seem
> reasonable to have them???
> 
> I'm not advocating mimicing PrintStream (which can
> be flaky in my view), all
> I'd like is support for more data types than just
> String...
> 
> In fact you answer the problem yourself, all I would
> like to have is JDOM
> make the String.valueOf calls myself so I don't have
> to clutter up my code
> and I get a standard interface to adding content.
> 
> As a final thing, in general if you are building up
> a document I have found
> it not uncommon to write code like:
> 
> 	Element el = new Element ("val").addContent (new
> Element
> ("val2").addContent (String.valueOf (x))));
> 
> The actual value added is lost at the end of the
> line under a
> String.valueOf...which may also be an expression,
> i.e.
> (System.currentTimeMillis () - starttime).  At least
> removing the
> String.valueOf shortens the line quite a bit.
> 
> Breaking up the code does not add any real
> readability either since it takes
> away the direct relationship between val and val2
> and gives more to read...
> 
> 	Element el = new Element ("val");
> 	Element valel = new Element ("val2");
> 	valel.addContent (String.valueOf (x));
> 
> ...
> 
> Anyone else any thoughts...also, what would be the
> problem with having a
> bigger API?  An API is supposed to make the
> application programmers life
> easier, so more, in general, is better...
> 
> G.
> 
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of
> Elliotte Rusty Harold
> Sent: Thursday, March 15, 2001 6:31 PM
> To: jdom-interest at jdom.org
> Subject: Re: [jdom-interest] Thoughts on...
> 
> 
> At 4:42 PM +0000 3/15/01, Gary Bentley wrote:
> >Hi,
> >
> >Could I request that there be new methods added to
> Element so that "text"
> >content can be added via primitive types and
> object.  In other words have:
> >
> >	Element.addContent (Object obj);
> >	Element.addContent (int val);
> >	Element.addContent (long val);
> >	Element.addContent (char val);
> >	Element.addContent (float val);
> >	Element.addContent (double val);
> >	Element.addContent (boolean val);
> >	Element.addContent (char[] vals);
> >
> >as well as: Element.addContent (String val);
> >
> >In other words have it similar to how PrintStream
> works.  Currently I have
> >to convert all my values myself, which is a pain.
> >
> 
> May I ask that this not be done? The question of how
> to properly
> convert a binary number such as a double into a
> decimal number, and
> then convert that into a string, is a much more
> complicated on than
> it appears at first glance. It requires significant
> input from the
> programmer as to what they want to happen in many
> different cases.
> The java.text.DecimalFormat class provides a proper
> APi for this.
> PrintStream() does not.
> 
> JDOM should not be burdened with the very difficult
> problem of how to
> convert a number to a String. We should let
> programmers do it as they
> see fit in their applications. If a programmer
> really does just want
> the default behavior of PrintStream, then it's
> straightforward to
> write
> 
> e.addContent(String.valueOf(x));
> 
> or
> 
> e.addContent("" + x);
> 
> Very little is gained by adding the proposed
> methods, though they do
> make the API larger and more complicated.
> --
> 
>
+-----------------------+------------------------+-------------------+
> | 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/     |
>
+----------------------------------+---------------------------------+
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
> t.com
> 
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/



More information about the jdom-interest mailing list