auto storage class - infer or RAII?
Tomas Lindquist Olsen
tomas at famolsen.dk
Mon Nov 13 10:32:17 PST 2006
Kristian Kilpi wrote:
> On Mon, 13 Nov 2006 19:24:21 +0200, Tomas Lindquist Olsen
> <tomas at famolsen.dk> wrote:
>
>> JC wrote:
>>> "Walter Bright" <newshound at digitalmars.com> wrote in message
>>> news:ej9acb$1sac$2 at digitaldaemon.com...
>>>> Tomas Lindquist Olsen wrote:
>>>>> *shivers* by the thought of 'var'
>>>> I knew that somehow I couldn't be the only one <g>.
>>> I don't see much wrong with 'var'.
>>
>> My issue with 'var' is that it looks ugly and doesn't really tell you
>> that RAII is in action.
>
> Well that's the point because 'var' isn't used with RAII but with type
> inference only. ;)
>
> 'var' just tells you that this is a variable declaration, and that's why
> I like it for TI.
>
Okay seems I misunderstood. Though I dont see why this makes it better.
'auto' as a storage class currently does everything 'var' would do. Only
reason this would make sense was if 'auto' was completely removed!
Still don't like the look of 'var' though...
>
>>> 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.
More information about the Digitalmars-d
mailing list