www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Semantics of toString

Justin Johansson Wrote:

 I assert that the semantics of "toString" or similarly named/purposed
methods/functions in many
 PL's (including and not limited to D) is ill-defined.
 To put this statement into perspective, I would be most appreciative of D NG
 responding with their own idea(s) of what the semantics of "toString" are (or
should be)
 in a language agnostic ideology.
 If there are more than, say, two or three different views on the said
semantics then my
 "ill-definition" assertion is surely correct.
 If there are no replies on this matter, then guess I'm left concludeless.
 Just thinking in the language round-up that this is (just another) one of the
 we should address as a community.
 So what does "toString" mean to you?
 **caveat: free beer offer available in-store only

Well some Java author said that the toSting method was only intended for debugging, but list containers use it so... I don't have that reference :( You can also check out the question on StackOverflow http://stackoverflow.com/questions/563676/is-tostring-only-useful-for-debugging But personally, output to the end-user should not come from toString and program logic should not be based on the string returned from toString.
Nov 05 2009