[jdom-interest] Legal values of line separator

Jason Hunter jhunter at acm.org
Mon Jul 10 10:09:19 PDT 2000


Elliotte Rusty Harold wrote:
> As a book author who occasionally feels compelled to
> exhaustively document every part of the public interface of a class,
> I think there's a real benefit  to keeping the API smaller and easier
> to grasp. 

Elliotte, you have a *very* sympathetic ear here.  :-)

> Adding the named constants would only really change the
> behavior or functionality of the class if those were the only strings
> one could pass to setLineSeparator(). If you can also invoke
> 
> outputter.setLineSeparator("\n")
> 
> then I suspect most programmers would be happy to do that. The
> syntactic sugar in
> 
> outputter.setLineSeparator(SEPARATOR_UNIX)

It's even worse:

  outputter.setLineSeparator(outputter.SEPARATOR_UNIX);

> just isn't sweet enough to tempt my palate given the calories it carries.
> 
> For similar reasons, if we're going to do line separators this way, I
> think we should get rid of the boolean newlines field. Instead, this
> functionality should be replaced by setting the line separator string
> to null or the empty string. For example, the constructor
> 
> public XMLOutputter(java.lang.String indent,
>                      boolean newlines,
>                      java.lang.String encoding)
> 
> would become
> 
> public XMLOutputter(java.lang.String indent,
>                      String lineSeparator,
>                      java.lang.String encoding)
> 
> and then we don't have to throw an exception on a null line separator either.

So we say in the Javadocs that the default line separator is "\r\n" but
tell people to pass "\n" for Unix or "\r" for Mac, or ""/null for no
line separations.  That works for me.

-jh-





More information about the jdom-interest mailing list