Nick Sabalausky a écrit :
"bearophile" <[email protected]> wrote in message news:[email protected]...
Andrei Alexandrescu:
If it were an error, I wouldn't let it go.
It's an error. It will lead to troubles.


Sometimes it is an error, but there are times when it isn't:
[cut]
Call List In Psuedo-Japanese:
For Each Person Where Name="Smith": "SmithSan {LoopIndex}'s DenwaBango: {Phone}"
---------------------

So then the report creation code:

---------------------
foreach(int i, Person p; people.subset(customReport.whereClause))
writefln(customReport.formatStr, i, p.id, p.first, p.last, p.phone, p.zip);
---------------------

That would be very difficult/limiting if every arg had to be used in the format string.

Mmmh, is {LoopIndex} correct? It should be {i} I think and I would argue that this format string should generate an error (something better than a runtime exception would be nice but I'm not sure that this is possible).

That said I agree that both are needed, so why not have either two different function or a function parameter which change the behaviour of the format string interpretation?

By default writefln would complain if there is a possibility of an unused parameter, but you could do writefln(customReport.formatStr, i, p.id, p.first, p.last, p.phone, p.zip, allowUnused=true);

(Incidentally, this example also demonstrates why I consider C#/Tango-style string formatting superior to C/Phobos-style)

I think that named format string are much superior to positional format string as they are easier to read/write..

BR,
renoX

Reply via email to