Suggestion for a D project/std module: templated format
Derek Parnell
derek at nomail.afraid.org
Tue Feb 20 15:50:58 PST 2007
On Tue, 20 Feb 2007 21:30:17 -0200, Miles wrote:
> Jarrett Billingsley wrote:
>> You mean like std.metastrings.Format? ;)
>
> Definitely no. Like you figured, std.metastrings.Format doesn't generate
> any run-time code. I want something that parses the format string at
> compile-time, and just convert and concatenate the arguments at run-time.
>
> Also, std.metastrings.Format only supports %s, so it does no
> type-checking and argument counting. If you provide more arguments than
> the format string asks for, they are just concatenated like the original
> format. This is something that helps bugs to pass unnoticed by the
> programmer.
>
> Definitely not what I want.
For what its worth, I tend to just use '%s' in writefln() calls, and almost
never use any of the other format codes, regardless of the data type being
supplied in the arguments.
e.g.
char[] theName;
int theAge;
std.stdio.writefln("Hi, my name is %s and I'm %s years old",
theName, theAge);
Thus I've chosen the chance of formatting bugs over the ease of coding. It
is no different to saying either ...
std.stdio.writefln("Hi, my name is %s and I'm %s years old",
toString(theName), toString(theAge) );
or
std.stdio.write("Hi, my name is ", theName,
" and I'm ", theAge,
" years old");
I'm not saying your idea is bad, just that its not going to be universally
wanted.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
21/02/2007 10:42:57 AM
More information about the Digitalmars-d
mailing list