auto storage class - infer or RAII?
Kristian Kilpi
kjkilpi at gmail.com
Mon Nov 13 10:55:53 PST 2006
On Mon, 13 Nov 2006 20:40:23 +0200, JC <johnch_atms at hotmail.com> wrote:
> "Kristian Kilpi" <kjkilpi at gmail.com> wrote in message
> news:op.tiyvn2xqusumhd at mist...
>>> It has the nice connotation that it represents a variable, at least.
>>
>> The other storage classes work for variables too!
>>
>>> As for RAII, just using a keyword alone doesn't seem to cut it. If
>>> references are to be automatically deleted at the end of a scope, that
>>> infers that a scope is actually introduced, which to me is signified by
>>> a matching pair of curly brackets. I'd like to be able to specify the
>>> extent of the scope, perhaps like this:
>>> void drawBox(Rectangle rect, Colour colour) {
>>> scope (DrawingContext dc = createDrawingContext()) {
>>> scope (Pen pen = new Pen(colour)) {
>>> dc.drawRectangle(pen, rect);
>>> } // pen is freed here
>>> } // dc is freed here
>>> }
>>> Used this way, 'scope' as the RAII keyword makes sense.
>>
>> *Please* no!
>
>> Also I don't like this syntax. All variables should always be declared
>> at
>> the begining of blocks.
>
> According to whom? That's a style thing, not a rule.
>
Yes, that was just my humble opinion. :)
I just think that it would be consistent if all the variables will be
declared in the same place. In addition, that would add an extra level of
indentation. I would like to write:
void func() {
int a;
scoped file = new File;
...
}
instead of:
void func() {
int a;
scope(file = new File) {
...
}
}
And it gets complicated when more than one scoped variable will be used,
IMHO.
More information about the Digitalmars-d
mailing list