Suggestion: shortcut for 'new X'
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Thu Aug 24 13:30:25 PDT 2006
Kristian wrote:
> 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'.
Well true, but
auto obj = new Obj();
is not much longer, also isn't redundant and it also tells everyone what
type 'obj' is.
More information about the Digitalmars-d
mailing list