Suggestion: shortcut for 'new X'

Kristian kjkilpi at gmail.com
Thu Aug 24 11:28:14 PDT 2006


On Thu, 24 Aug 2006 21:17:23 +0300, BCS <BCS at pathlink.com> wrote:

> Kristian wrote:
>>  However, I don't think that it's good programming style to use auto a   
>> lot. :/
>>
>
> substitute excessive for a lot and I agree.
>
>> Consider the following:
>>  Obj func2() {...}
>>  void func() {
>>     auto obj = func2();
>> }
>>  When looking at 'func()' only it's impossible to know the type of  
>> 'obj'.
>
> that can be a bit of a gotcha. I haven't done it but putting in a
>
> static assert(is(obj : Obj));
>
> could serve as a bit of type documentation and as a guard against API  
> changes.

That's too hackish to my taste, and who have energy to write such long  
statements for simple variable declarations? ;)

Better have a simple, clear way to declare a variable, haven't it?

"Obj obj = new;" is short, non-redundant, and it tells everybody that  
'obj' is of type 'Obj'.



More information about the Digitalmars-d mailing list