Suggestion: shortcut for 'new X' #2
kjkilpi at gmail.com
Tue Sep 5 12:07:34 PDT 2006
On Tue, 05 Sep 2006 21:35:13 +0300, Ivan Senji
<ivan.senji_REMOVE_ at _THIS__gmail.com> wrote:
> Kristian wrote:
>> Ok, I think my previous suggestion for an optional shortcut was a bit
>> too strange... For example:
>> Foo f = new Foo;
>> Bar b = new Bar(10);
>> Foo f = new;
>> Bar b = new(10);
>> Now there has been a proposal of the following (I use 'local' keyword
>> Foo f1 = local Foo; //stack/RAII
>> Foo f2 = new Foo; //heap
>> I like the syntax also.
>> How about if you could *alternately* write:
>> local Foo f1;
>> new Foo f2;
>> This would take care of the redundant class name in the declarations.
>> (I just hate redundance! ;) Writing class names twice is frustrating;
>> there is a pattern of "X ... X".)
>> Constructor parameters are put after variable names:
>> local Bar b(10);
>> new Bar b(10, true);
>> If this (or something similar) is not possible, a lot of people
>> (including me) could end writing auto typed declarations. For example
>> (auto here means auto type, not RAII):
>> auto f = new Foo;
>> auto b = new Bar(10);
> And I still don't see what is so terribly awful about that?
Hehheh, maybe I'll get used to it over the time if I have to...
>> That could be shortened to:
>> f = new Foo;
>> b = new Bar(10);
>> Which leads to my suggestion:
>> new Foo f;
>> new Bar b(10);
> Hmm, that looks a little to strange to me. It looks more like an
> expression than a declaration.
local Foo f;
looks more like a declaration?
Maybe 'new' shouldn't be used with this syntax. (Or use "new var Foo
f;"... or not.)
I am trying to found out a syntax that has one type name and a variable
name, and in that order.
local File f;
auto f = local File;
More information about the Digitalmars-d