dmd 2.029 release

Nick Sabalausky a at a.a
Mon Apr 20 15:07:58 PDT 2009


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:gsipn1$1bng$1 at digitalmars.com...
> 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:

Suppose you're writing a reporting module for an employee database:

---------------------
ID: 3234
Last: Doe
First: John
Phone: 555-5555
Zip: 90210

ID: 7642
Last: Smith
Etc...
---------------------

And you want the admins to be able to define their own reports:

---------------------
Privileged Report:
For Each Person: "ID #{ID}\nName: {First} {Last}\nPhone: {Phone}\nZip:{Zip}"

Unprivileged Report:
For Each Person: "Name: {Last}, {First}\nContact Info Classified"

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.

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




More information about the Digitalmars-d-announce mailing list