Semantics of toString
grauzone
none at example.net
Tue Nov 10 07:48:20 PST 2009
Don wrote:
> grauzone wrote:
>> Don wrote:
>>> Lutger wrote:
>>>> Don wrote:
>>>> ...
>>>>> There is a definite use for such as thing. But the existing toString()
>>>>> is much, much worse than useless. People think you can do something
>>>>> with
>>>>> it, but you can't.
>>>>> eg, people have asked for BigInt to support toString(). That is an
>>>>> over-my-dead-body.
>>
>> How are you supposed to print a BigInt then?
> How are you supposed to print one with it? It doesn't help.
> (The problem even more obvious if you consider BigFloat).
>
>> Just put it into an "interface DebugOutput", remove Object.toString(),
>> and be done with it. That interface could be defined in the same
>> module as writefln or format, and its use will be clear.
>
> BigInt is a struct, so it doesn't have interfaces.
Structs are a different matter. Nothing dictates that a struct should
have a toString method, or what arguments that method should have,
right? (There's this compiler/runtime hack to make struct toString work
with writefln, but now that wirtefln uses compile time varargs, it can go.)
More information about the Digitalmars-d
mailing list