Walter: Before you go and implement the new RAII syntax..
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Sep 4 21:55:56 PDT 2006
This is what I'm talking about:
Foo f = Foo(); // RAII
Foo g = new Foo(); // Normal
Can we all discuss this? I'm sorry, but that syntax is just too easy to
mess up / miss. I'm surprised that you, someone who is very much against
"secret things happening" would be a proponent of this syntax. It's just
too nonobvious. (And as a minor point, this also makes it impossible to
make a static opCall with a class.)
How about instead, we keep auto to mean a RAII reference, and we take the C#
route for type inference and come up with a "var" keyword which would be a
"type placeholder". That is:
var f = new Foo(); // Normal
auto var g = new Foo(); // RAII
And as you can see, this gets rid of thee "auto auto" problem. Not to
mention it gets rid of the very common misunderstanding that currently,
"auto" is somehow used for type inference, when in fact it's simply the use
of a storage class without a type that invokes type inference.
This, or maybe we could use a "stack" or "local" or "raii" keyword in place
of the "new":
Foo f = stack Foo();
Foo g = local Foo();
Foo h = raii Foo();
Something. Anything would be better than the "new or nothing" syntax.
More information about the Digitalmars-d
mailing list