Is D 0.163 D 1.0?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Sun Jul 23 22:37:00 PDT 2006
Andrei Khropov wrote:
> And what about double meaning of 'auto'?
>
> It's a longstanding issue and changes could break lots of code, but I think it's
> a terrible design inconsistency.
>
> And it also currently means that we cannot use type inference with auto classes
> (which is also inconsistensy by itself)
>
> ------------------------------------------------
> import std.stdio;
>
> auto class X
> {
> public:
> int _i;
>
> this(int i1)
> {
> _i = i1;
> }
>
> int i()
> {
> return _i;
> }
>
> ~this()
> {
> writefln("destructor i=",_i);
> }
> }
>
> void main()
> {
> auto X x1 = new X(1);
>
> //auto auto x2 = new X(2); // auto1.d(28): redundant storage class 'auto'
>
> // auto x3 = new X(3); // auto1.d(30): variable auto1.main.x3 reference to
> auto class must be auto
>
> writefln("x1.i=",x1.i);
> //writefln("x2.i=",x2.i);
> //writefln("x3.i=",x3.i);
> }
> ---------------------------------------------------
>
> Some discussion was here:
> http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/38443
>
> (I personally vote for 'var' for type inference)
>
Agreed, and I've caught myself more than once starting to type this "auto auto" mess. And
I also agree with "var" as a good choice for doing this. I'm already used to using "var"
in other platforms, including PHP, ECMAScript, and my own Bovis language.
##### PHP
# class Foo {
# var $someField = 42 ;
# }
##### ECMAScript
# var x = 27 ;
##### Bovis
# var 'Any $foo = 99 ; // the 'Any specifier is optional, of course
And I believe this is what is used in the new edition of C# for type inference, yes? (I
haven't touched C# since the 1.0 so someone let me know if I'm wrong.) Precedence has
been established for it. It shouldn't be un-intuitive to many people.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d
mailing list