Semantics of toString
Lutger
lutger.blijdestijn at gmail.com
Sun Nov 8 15:16:56 PST 2009
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 readers responding with their own idea(s) of what the semantics of
> "toString" are (or should be) in a language agnostic ideology.
>
My other reply didn't take the language agnostic into account, sorry.
Semantics of toString would depend on the object, I would think there are
three general types of objects:
1. objects with only one sensible or one clear default string
representations, like integers. Maybe even none of these exist (except
strings themselves?)
2. objects that, given some formatting options or locale have a clear string
representation. floating points, dates, curreny and the like.
3. objects that have no sensible default representation.
toString() would not make sense for 3) type objects and only for 2) type
objects as part of a formatting / localization package.
toString() as a debugging aid sometimes doubles as a formatter for 1) and 2)
class objects, but that may be more confusing than it's worth.
More information about the Digitalmars-d
mailing list