auto, var, raii,scope, banana

Nils Hensel nils.hensel at web.de
Fri Jul 28 00:48:16 PDT 2006


Don Clugston schrieb:
> No, the idea is *not* to have a type inference keyword, but instead only 
> specify the storage class:
> 
> static a = 7;
> const b = 7;
> auto  c = 7;
> 
> Now 'a' is a variable, just as much 'c' is.
> 
> Are you proposing that you'd have to type:
> 
> static var x =  func(7);
Actually yes. I find it to be clearer than just static x.

> ? Surely not. 'const var' would be an abomination!
I agree on that. "const x = 5;" is expressive enough in its own way. But 
I never said variables and constants should be treated the same.


> The problem is, there's no storage class for local variables. In C/C++, 
> there is, and it's called 'auto', but it's extremely rarely used in 
> normal code. 'local' is perhaps the most natural name.
Also agreed. I find "local" much better than "auto". But I'm afraid we 
have to carry this ugly legacy.
The unexpressiveness of "auto" might be my whole problem with type 
inference as it is. Using storage classes for detection is a rather 
clever idea.

> I just don't like the idea that 'var' would mean "local non-static 
> variable". "Variable" is a much broader category than "local variable".
You have a point. But it is definitely the most often used type and what 
I believe most people think of when they hear "variable".


> I hope that one day D also gets explicit thread-local variables. They 
> would need a seperate storage class.
Sounds good to me.


>>> Agreed, but the 'auto' thing ultimately comes from C, not C++.
>> Yes, but not in the context of type inference. So the C "auto" is 
>> totally different from it's current D counterpart.
> 
> No, it's not. It's a storage class in C++, *not* a type inference 
> keyword. It's just that it's a storage class that in modern times is 
> only used in the context of type inference.
I think that's the same ugly legacy. I think D should drop things that 
are better expressed in a different way.


> I think 'var' makes much more sense for dynamically typed languages. 
> Still, I just learned that C# 3.0 is going to use it.
> What is the C# 3.0 type inference syntax? How does it deal with type 
> inference of constants?
Good question. But my guess is that for variables it's something like 
what you described above and that "const" does not get a "var". But it's 
just a guess.

Regards,
Nils



More information about the Digitalmars-d mailing list