directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Karasulu <akaras...@gmail.com>
Subject Re: [Code Issues] Don't use toString() to pretty print
Date Sun, 30 Aug 2009 19:46:44 GMT
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().

Alex

On Sun, Aug 30, 2009 at 10:37 PM, Emmanuel Lecharny <elecharny@apache.org>wrote:

> Alex Karasulu wrote:
>
>> Let's stop playing Picasso with the toString() method please.  This method
>> should be chosen carefully. I've already gotten bit a few times because
>> this.
>>
>>
> I would say that toString() methods are mostly valuable for logs and debug
> purposes. Any other usage is a violation of the contract, which is
> summarized by Joshua Bloch in his book (effective Java) :
>
> The general contract for toString says that the returned string should be
> “a concise but informative representation that is easy for a *person* to
> read”.
>
> Expecting that the toString() method will return something that should be
> processed by a program exceed the contract.
>
> I don't think that we should play Picasso either. Something closer to hyper
> realism painting is probably more appropriate.
>
> There is one exemple of bad usage of toString() in the server :
> LdapDN.toString(). And there is a JIRA about it :
> https://issues.apache.org/jira/browse/DIRSERVER-808
>
> In most of the case where the format of the printed object is already well
> defined, we should not try to put the nose over the left eye, and the mouth
> close to the belly... LdifEntry.toString() is most certainly not respecting
> the spirit of the toString() method...
>
>  Thanks,
>>
>>
>>
>
>
> --
> --
> cordialement, regards,
> Emmanuel Lécharny
> www.iktek.com
> directory.apache.org
>
>
>


-- 
Alex Karasulu
My Blog :: http://www.jroller.com/akarasulu/
Apache Directory Server :: http://directory.apache.org
Apache MINA :: http://mina.apache.org

Mime
View raw message