auto storage class - infer or RAII?

Bill Baxter wbaxter at gmail.com
Sat Nov 11 17:19:33 PST 2006


Derek Parnell wrote:
> On Sun, 12 Nov 2006 10:44:37 +1100, Derek Parnell wrote:
> 
> 
>>On Sat, 11 Nov 2006 10:48:00 -0800, Walter Bright wrote:
>>
>>
>>>The auto storage class currently is a little fuzzy in meaning
>>>class Class { }
>>>
>>>1) auto c = new Class();
>>>2) auto Class c = new Class();
>>>3) auto c = some_expression();
>>>4) auto Class c = some_expression(); 

>>>5) auto c = Class(); 

At least the first 4 have some consistent logic behind them, but #5 is 
just pure special casing for something that's not all that common or 
special.  It should just be

     auto auto c = new Class();

Besides Class may have a static opCall, no?

Anyway, to me, all these things look harder to disinguish than even the 
a..b vs a...b thing, which you didn't like, so I'm baffled as to why you 
are so resistant to make 'auto' usages easier to distinguish.

> By the way, I refuse to use the current 'auto' nowadays precicely because
> it adds to the cost of code maintenance, due to its ability to confuse
> and/or mislead code readers.

Agreed.  I stick with auto for auto-type inference, but I don't go near 
the other usage because it's just too confusing to have two different 
kinds of auto's in my code that can appear in such similar syntactic 
situations.  I have my preferences as already stated, but I would be 
satisfied, if not overjoyed, with any solution that
   A) makes the keywords for RAII and ATI distinct, and
   B) doesn't make the ATI keyword any longer than it already is.

Part of why I want auto for ATI to be short is that will get a lot of 
use.  There are already 50 or so uses of auto in phobos/std/*.d.  It 
looks like maybe 2 are RAII things but the rest are all ATI.

So ATI is more common than RAII.  Maybe ATI is common enough that it 
even warrants special syntax?  If so then I think the at-sign makes 
sense for that. "AuTo"->"at" -- close enough for a mnemonic.  That would 
mean "auto foo" could be compressed to "@foo".

Some examples of what it would look like:

    @ foo = some_expression();
    @bar = other_thing();

    for (@v = start; v<end; v++) {...}

    if (@m = std.regexp.search("abcdef", "c()"))

    @dim = this.dim();

    sort(list, @(@a, at b){ return a.val-b.val; }
      // though I think in this case it should be allowable to omit the
      // auto's/@'s and just have sort(list, (a,b){...});

--bb



More information about the Digitalmars-d mailing list