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

Kristian kjkilpi at gmail.com
Tue Sep 5 09:49:48 PDT 2006


On Tue, 05 Sep 2006 19:30:30 +0300, Robert Atkinson  
<Robert.Atkinson at NO.gmail.com.SPAM> wrote:
[snip]
> I believe that if we keep the auto/auto syntax, it will be a feature  
> that everyone will love at first, but years from now it'll be the  
> feature that we'll be cursing when we all have to maintain code.  
> Scanning code quickly its hard to determine with the current auto/auto  
> syntax if its RAII or auto typing.
>
> Rob

Well, I got confused right away (when I discovered D). ;) (And hence never  
liked the auto/auto syntax.)

I think it really should be changed.


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




More information about the Digitalmars-d mailing list