Feature request - simpler constructors

Bill Baxter dnewsgroup at billbaxter.com
Thu Sep 20 08:21:35 PDT 2007


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 to mean more or 
less what it means in declarations:

     void foo(auto y = "hi there",
              auto x = 23.f,
              const z = ABigNamedStruct())
     {. . . }

And having it mean something slightly different for 'this' methods than 
for an ordinary 'foo' method would just be confusing.

--bb



More information about the Digitalmars-d mailing list