auto, var, raii,scope, banana
Regan Heath
regan at netwin.co.nz
Mon Jul 31 19:02:48 PDT 2006
On Sat, 29 Jul 2006 21:20:22 +0100, Bruno Medeiros
<brunodomedeirosATgmail at SPAM.com> wrote:
> Regan Heath wrote:
>> On Tue, 25 Jul 2006 23:28:24 -0400, Chad J
>>> I really don't like the idea of dropping a language feature just for
>>> the sake of having a particular syntax that, IMO, is not intuitive.
>> It's the same syntax you see in C++ for a class that has it's
>> destructor called at the end of the scope. That, to me, makes it
>> intuitive. For what reason do you find it un-intuitive?
>>
>
> Are you saying it is intuitive because *it is the same syntax as C++* ??
> I hope not, because being the same syntax as C++ not only does not make
> it intuitive, but it also likely has the inverse effect: making things
> un-intuitive.
I was in fact wrong about the syntax being the same.
That said, syntax and behaviour which is similar to C++ is intuitive (to
C++ programmers). That's all I sugested (you need to read my statement in
context with the example of the C++ and Java/C# programmers).
I was attempting to compare the 2 proposals:
- absence of 'new'
- use of keyword 'scope' or 'local' or <insert favourite keyword>
by describing how a programmer from either the C++ or Java/C# world might
encounter the RAII syntax, as far as I can see they'll either:
1. read some code using it.
2. want to implement RAII and will search the docs.
I don't think either method is significantly better or worse in these 2
situations regardless of the programmers background.
My mistake was that I thought the "absence of new" syntax was the same as
the C++ syntax (for stack allocated, destroy at end of scope classes).
This would have made it 'more' intuitive to the general population by
virtue of being 'more' intuitive to the C++ programmers.
In fact, if the suggested RAII syntax was:
class A {}
A a; //allocate RAII class
then the C++ programmer, who wrote the above for his/her first D program
wouldn't get an access violation (as they currently do) and would instead
get the expected behaviour. An object (not allocated on the stack.. yet)
whose destructor is called at end of scope.
So, perhaps the RAII syntax should be this? It benefits C++ programmers
and does not hurt Java/C# programmer any more than having to learn and use
a new keyword (as it's essentially the same thing)
Regan
More information about the Digitalmars-d
mailing list