November 13, 2006
Carlos Santander wrote:
> Also keep in mind that your option #5 (auto c = Class()) doesn't seem to be a popular proposal (based on what has been said in the ng).

I for one would like it!

It's much closer to C++. It hides the "new" and eventually might even be changed to allocate memory using the stack instead of the heap. It will be incompatible with static opCall (which I find hackish anyway) so people will probably ask for a way to add constructors to structs.

L.
November 13, 2006
Walter Bright schrieb:
> I think the auto/scope is probably the best idea.

I have to agree, even though I was among the first to shout out against "auto". I have changed my mind since.

Using a storage class for type inference is an easy and coherent method and since C++ will use "auto" for type inference it isn't such a bad choice after all. Perhaps I got used to it after all.

I still think though that it should only mean that. My favourite choice for stack variables would be "local". It's short and completely obvious though I could live with "scope" if you want to avoid a new keyword at all costs.

Cheers,
Nils
November 13, 2006
"Walter Bright" <newshound@digitalmars.com> wrote in message news:ej9acb$1sac$2@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'. It has the nice connotation that it represents a variable, at least.

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.


November 13, 2006
JC wrote:

> 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.

Heh, that's exactly how 'using' is used in C#.
I prefer usual C++ - like RAII style.

-- 
AKhropov
November 13, 2006
Andrey Khropov wrote:
> JC wrote:
> 
> 
>>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.
> 
> 
> Heh, that's exactly how 'using' is used in C#.
> I prefer usual C++ - like RAII style.

Ugh yes.  Please don't force any more extra indentation levels on us! Its bad enough with 'with' already.
If you want a new indentation level for every single scoped variable then feel free to make scopes for them all,

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
}

but don't force everyone to do that.

--bb
November 13, 2006
Bill Baxter wrote:
> Tomas Lindquist Olsen wrote:
>> Walter Bright wrote:
> 
>> I'd like to see 'scoped' as a new storage class for classes and dynamic arrays. Using it for anything else should be an error. This would mean that 'auto class' would become 'scoped class' too.
> 
> I think
> 
>   scoped int a = expr;
> 
> should be ok. Allowing that enables you to treat value types and classes uniformly in some template usages.
> 
>     {
>        scoped T a = make_temp_var();
>        ...
>     }
>     // a has been cleaned up here, whether it was a class or not
> 
> I don't have a specific use case in mind, but it seems there's no reason to not allow it, since a basic value type acts like it's scoped anyway.
> 
> 
> --bb
I think you are right. Hadn't thought of this.
November 13, 2006
JC wrote:
> "Walter Bright" <newshound@digitalmars.com> wrote in message news:ej9acb$1sac$2@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.

> 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!
November 13, 2006
== Quote from Tomas Lindquist Olsen (tomas@famolsen.dk)'s article
> JC wrote:
> > "Walter Bright" <newshound@digitalmars.com> wrote in message news:ej9acb$1sac$2@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.

But I think 'var' would mean type inference, not RAII.

> > [...]
November 13, 2006
On Mon, 13 Nov 2006 19:24:21 +0200, Tomas Lindquist Olsen <tomas@famolsen.dk> wrote:

> JC wrote:
>> "Walter Bright" <newshound@digitalmars.com> wrote in message news:ej9acb$1sac$2@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.


>> 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.
November 13, 2006
Kristian Kilpi wrote:
> On Mon, 13 Nov 2006 19:24:21 +0200, Tomas Lindquist Olsen <tomas@famolsen.dk> wrote:
> 
>> JC wrote:
>>> "Walter Bright" <newshound@digitalmars.com> wrote in message news:ej9acb$1sac$2@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.