Re: toString() convention

View: New views
1 Messages — Rating Filter:   Alert me  

Re: toString() convention

by Alan.Cabrera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think that Spring's formatting conventions are pretty nice.  What  
does get put into string would be a matter of common sense.


Regards,
Alan

On Jul 7, 2008, at 10:13 AM, Alan D. Cabrera wrote:

> Agreed.  What I was thinking was what kind of debug info?  For  
> example, do we print the class name?  What about array/map members?
>
>
> Regards,
> Alan
>
> -----Original Message-----
> From: "Simone Bordet" <simone.bordet@...>
> To: dev@...
> Sent: 7/7/2008 9:20 AM
> Subject: Re: [livetribe-dev] toString() convention
>
> Hi,
>
> On Mon, Jul 7, 2008 at 5:52 PM, Alan Cabrera <adc@...>  
> wrote:
>> I know that this might be a fussy topic but I think that we should  
>> have
>> standards on what gets printed in toString().
>>
>> Thoughts?
>
> Well, this is my take: I use toString() for debugging purposes and  
> that's it.
> If I want to stringify an object I usually add a new method, most of
> the times called "asString" that stringifies the object as needed by
> the business requirements (see Attributes.asString()).
>
> I don't want to rely on toString(), because it happened to me that I
> overrode toString() to return a particular string (that was indeed
> representing the object) needed by the business; then discovered that
> the information returned was not enough when I was printing the object
> in debug statements, so I modified toString() to return the additional
> information, but this of course broke the place where toString() was
> used as a business method.
>
> There is also another good reason to avoid toString() to become a
> business method: it messes up with interfaces, see for example
> o.l.slp.spi.filter.Filter. If toString() is used instead of
> asString(), then you're not anymore forced to implement it (because it
> is automatically implemented in Object). Bad for IDEs (that do not
> show you that you *must* implement it).
>
> So my rule is: don't use toString() as a business method; otherwise, I
> don't care how it is implemented.
>
> Simon
> --
> http://bordet.blogspot.com
> ---
> Finally, no matter how good the architecture and design are,
> to deliver bug-free software with optimal performance and reliability,
> the implementation technique must be flawless. Victoria Livschitz
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email