January 30, 2004 Re: [Properties] Design bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | Andy Friesen wrote:
> Since D now has the typeof() construct, D could just disallow
[...]
That is a good one.
The standard properties should be only reachable via `typeof()'.
This prevents the need to disallow the names of standard properties in derived types or to make them keywords.
And because it is somehow inconvenient to write `typeof(int).sizeof' syntactic sugar for the types `T' predeclard with keywords should be given, to write `T.sizeof', i.e. `int.sizeof'.
So long.
|
January 31, 2004 Re: [Properties] Design bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | Manfred Nowak wrote:
>
> ... because it is somehow inconvenient to write `typeof(int).sizeof' syntactic sugar for the types `T' predeclard with keywords should be given, to write `T.sizeof', i.e. `int.sizeof'.
>
Right. That's already valid D, though, so it's not a big deal.
ie
int a;
int.size; // good
typeof(a).size; // good
a.size; // bad
The only remaining issue, of course, is types that have static attributes or methods whose names coincide with the builtins.
-- andy
|
January 31, 2004 Re: [Properties] Design bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | Andy Friesen wrote: >> to write `T.sizeof', i.e. `int.sizeof'. > Right. That's already valid D, though, so it's not a big deal. Upps. It is not only valid D. It causes an error to write`typeof(int)'. And I meant to type `T.sizeof' only when `T' is represented by its keyword. > ie > int a; > int.size; // good > typeof(a).size; // good > a.size; // bad In this case I would like dmd to create: | test.d(4): use 'typeof(a).size' to access standard property > The only remaining issue, of course, is types that have static attributes or methods whose names coincide with the builtins. Why is that an issue? If and only if the values of standard properties can be accessed trough `typeof()', whilst non standard properties can only be accessed directly, there is no problem at all. I.e.: class Foo { static int sizeof() { return 6; } int size() { return 7; } } class Bar { int value() { return 8; } } void main(){ int i; Foo f= new Foo; Bar b= new Bar; i=Foo.sizeof; // produces 6 //i=Foo.size; // error: no 'this' for non-static member functions //i=Bar.sizeof; // error: use 'typeof(Bar).sizeof' to access // standard property i=f.sizeof; // produces 6 i=f.size; // produces 7 //i=b.sizeof; // error: use 'typeof(b).sizeof' to access standard // property i=b.value // produces 8 i=typeof(Foo).sizeof; // produces the value of the named property i=typeof(Foo).size; // " (currently) i=typeof(Bar).sizeof; // " //i=typeof(Bar).value;// error: no standard property 'value' for // expression 'Bar' i=typeof(f).sizeof; // produces the value of the named property i=typeof(f).size; // " (currently) i=typeof(b).sizeof; // " //i=typeof(b).value; // error: no standard property 'value' for // expression 'b' } Note: the so called properties of Classes and Structs currently can not be accessed through `typeof()'. So its also not a big deal. So long. |
Copyright © 1999-2021 by the D Language Foundation