Walter: Before you go and implement the new RAII syntax..

Derek Parnell derek at nomail.afraid.org
Mon Sep 4 22:04:30 PDT 2006


On Tue, 5 Sep 2006 00:55:56 -0400, Jarrett Billingsley wrote:

> 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.

I strongly agree with Jarrett. 

     Foo f = <NEW> Foo();

  where <NEW> can be either 'new' or 'local', or even 'new local' but never
omitted, when invoking the class constructor. The static opCall is probably
not valuable and if removed I wouldn't mind, but this still would not
justify omitting 'new' either.

BTW, I'm not wedded to 'local' but something, ... anything, that explicitly
informs the reader that the object will be destroyed when it goes out of
scope is needed. Leaving it out is not a good user interface.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
5/09/2006 2:57:59 PM



More information about the Digitalmars-d mailing list