auto, var, raii,scope, banana | "def" for autotype

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sat Jul 29 14:17:55 PDT 2006


kris wrote:
> Don has a good point: changing to "var" would cause conflict with 
> existing variable-names.
> 
[...]
> 
> I suspect you could count the current number of raii-class uses on a few 
> hands, whereas the use of "auto" for implied-type is pretty darned 
> popular -- and rightly so, since it's really very, very useful. Changing 
> the raii style to use a different keyword, whilst retaining implied-type 
> "auto" would be an almost imperceptible change?
> 
> Thus, it would appear to make sense to retain "auto" for implied-type, 
> and introduce something *else* for automatic cleanup at end-of-scope 
> (and also as a class attribute). how about reusing the "scope" keyword?
> 
> void main()
> {
>   auto i = 10;
>   auto foo = new Foo;
>   auto scope bar = new Bar;
>   auto scope wumpus = new Wumpus;
> }
> 
> class Foo {}
> 
> class Bar {}
> 
> scope class Wumpus {}
> 

Up to now, I favored the following keyword proposals:
   "auto" -> for RAII (autoraii or raiiauto)
   "var" -> for implicit type deduction. (autotype)

The idea that autotype is the most used auto notion, and as such should
be the one not to change it's keyword has no support from me. (Although
I agree Walter I very resilient towards keyword changes...)

When I think the name "auto", I think the most close meaning is that of
automatic allocation/decallocation (raiiauto) and not implicit type
deduction. And I quite deslike the name "scope" (or even "scoped") for
raiiauto, (subjective point)

As for autotype, exactly because it is used often I liked the fact that
"var" is one character shorter. I also liked that it was the same as C#
3.0. But I do agree there is some strangeness to see "var" used as such
keyword for type deduction, so I wasn't 100% happy.

How about "def" for autotype keyword? It's still one char shorter, and I
think the name is pretty nice:
   def n = 42;
   def foo = new Foo();
The syntax similarity to dynamic languages is also somewhat... appealing :)


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list