Feature request - simpler constructors

kris foo at bar.com
Thu Sep 20 09:02:41 PDT 2007


Bill Baxter wrote:
> 
> 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


I agree, and there more. The example given suggested

# this(auto year, auto month, auto day, auto hour, auto minute, auto second)

in such a case, one is invariably also going to provide something like:

# set (int year, int month, int day, int hour, int minute, int second)

or a combination of:

# date (int year, int month, int day)
# time (int hour, int minute, int second)

Hence, the ctor should actually be:

# this (int year, int month, int day, int hour, int minute, int second)
# {
#    date (year, month, day);
#    time (hour, minute, second);
# }

Having the compiler "fill in the gaps" here is just sloppy IMO. Do it 
right the first time.

Further, it's common practice (in D) to name local vars somewhat 
different than the parameter names, so that DDoc has something nicer to 
show (recall that ppl often use prefix/postfix decoration on member 
vars, to avoid name conflict with internal functions). This 'auto' 
notion would simply increase the level of brittleness involved. There's 
other reasons too, but all in all I suspect this notion is borne from 
pure laziness rather than from an engineering perspective?






More information about the Digitalmars-d mailing list