directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@apache.org>
Subject Re: [Code Issues] Don't use toString() to pretty print
Date Sun, 30 Aug 2009 21:58:47 GMT
Alex Karasulu wrote:
> OK to be more clear on what I desire:
>
> We have things like getString() and toString().  Sometimes we have pretty
> print functionality in toString().  If you have an object which you want
> turned into a string representation toString() might just do the job like
> for an Enum or something like that.  You basically intuit that you can
> toString() the damn thing.  Like Value.toString() is the string value.
>
> If you want to have some extensive pretty print output for debugging and
> logging then put that into a getPrettyString() or something like that
> instead of toString().  Value or some other object out there like the
> SchemaObject and subclasses have the toString() doing a pretty print and I
> just wanted the string representation of the value.  If I want to pretty
> print something then let's just have a toPrettyString() or something very
> explicit.  Hard to tell if I should use Value.toString() or
> Value.getString().
>   
Well, again, toString() is used for logging or, most important, 
debugging purpose. In this case, the more we have, the prettier it is, 
the better.

However, as I said,  when the String format is very well known, then 
adding some information is useless (like printing a LdifEntry as 
something not looking like a LDIF).

I insist on the debugging point because the toString() method is what is 
used by *all* the IDE when you want to watch a variable.

getPrettyString() is most certainly not the good thing to use in this 
case, you can't use it while debugging.

-- 
--
cordialement, regards,
Emmanuel L├ęcharny
www.iktek.com
directory.apache.org



Mime
View raw message