Feature request - simpler constructors

Bill Baxter dnewsgroup at billbaxter.com
Thu Sep 20 13:43:10 PDT 2007


Ary Manzana wrote:
> Bill Baxter escribió:
>> Steven Schveighoffer wrote:
>>> "Bill Baxter" wrote
>>>> I like the idea but I'm not wild about the syntax you've chosen.  
>>>> I'd like to be able to read off the types of the parameters from the 
>>>> function signature without having to dig around in the class for 
>>>> where the memebers are defined.  What about something like prefixing 
>>>> the name with a dot?
>>>>
>>>>
>>>>    this(int .year, int .month, int .day, int .hour, int .minute, int 
>>>> .second)
>>>
>>> Personally, I like Janice's idea better.  It should be up to the IDE 
>>> to tell you what the types are for the constructor.
>>>
>>> Imagine a situation like this:
>>>
>>> class X
>>> {
>>>    int y;
>>>    this(int .y) {}
>>> }
>>>
>>> Now the author decides y should be a long:
>>>
>>> class X
>>> {
>>>    long y;
>>>    this(int .y) {}
>>> }
>>>
>>> Oops, forgot to update the constructor.  But the compiler won't 
>>> complain because this.y = y is valid.  With Janice's syntax, this 
>>> doesn't happen.
>>>
>>> -Steve
>>
>> I guess the main worry lurking in the back of my mind is that we may 
>> actually want to use auto in parameter lists someday
> 
> Well, it could be the keyword "this", and it also has a closer meaning 
> to what's actually done.
> 
> class Point {
> 
>   int x;
>   int y;
> 
>   this(this x, this y) {
>   }
> 
> }

Ooh.  I do like that a lot better.

--bb



More information about the Digitalmars-d mailing list