www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Remove declaration 'auto' for RAII?

reply "Chris Miller" <chris dprogramming.com> writes:
There is a problem with auto when declaring variables!

Not only does it have 2 meanings, but when using it for implicit type  
inference, it no longer has the RAII quality. So if you say "auto foo = 1"  
is much like "static bar = 1", you are mistaken. The 2nd one doesn't cause  
it to be non-static, so why does the 1st make it non-RAII?

If auto for implicit type inference stays, I propose removing it for RAII  
in declarations. If you want RAII you can simply use scope(exit) delete  
baz; after the declaration. Also, the "auto class {}" form can still stay  
since it is in unrelated code and there is no easy replacement for it.
Mar 13 2006
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Chris Miller" <chris dprogramming.com> wrote in message 
news:op.s6csodzipo9bzi moe...
 There is a problem with auto when declaring variables!

 Not only does it have 2 meanings, but when using it for implicit type 
 inference, it no longer has the RAII quality. So if you say "auto foo = 1" 
 is much like "static bar = 1", you are mistaken. The 2nd one doesn't cause 
 it to be non-static, so why does the 1st make it non-RAII?

 If auto for implicit type inference stays, I propose removing it for RAII 
 in declarations. If you want RAII you can simply use scope(exit) delete 
 baz; after the declaration. Also, the "auto class {}" form can still stay 
 since it is in unrelated code and there is no easy replacement for it.
Sigh.. was it really necessary to start another thread about this?
Mar 13 2006
parent reply Tom <Tom_member pathlink.com> writes:
In article <dv3u5j$2ot1$1 digitaldaemon.com>, Jarrett Billingsley says...
"Chris Miller" <chris dprogramming.com> wrote in message 
news:op.s6csodzipo9bzi moe...
 There is a problem with auto when declaring variables!

 Not only does it have 2 meanings, but when using it for implicit type 
 inference, it no longer has the RAII quality. So if you say "auto foo = 1" 
 is much like "static bar = 1", you are mistaken. The 2nd one doesn't cause 
 it to be non-static, so why does the 1st make it non-RAII?

 If auto for implicit type inference stays, I propose removing it for RAII 
 in declarations. If you want RAII you can simply use scope(exit) delete 
 baz; after the declaration. 
Sorry, why to do that? I don't want to be forced to free every object manually with scope(exit)? Then it wouldn't be RAII anymore! Or I don't understand your point.
 Also, the "auto class {}" form can still stay 
 since it is in unrelated code and there is no easy replacement for it.
Sigh.. was it really necessary to start another thread about this?
Tom;
Mar 13 2006
parent reply "Chris Miller" <chris dprogramming.com> writes:
On Mon, 13 Mar 2006 10:02:49 -0500, Tom <Tom_member pathlink.com> wrote:

 In article <dv3u5j$2ot1$1 digitaldaemon.com>, Jarrett Billingsley says...
 "Chris Miller" <chris dprogramming.com> wrote in message
 news:op.s6csodzipo9bzi moe...
 There is a problem with auto when declaring variables!

 Not only does it have 2 meanings, but when using it for implicit type
 inference, it no longer has the RAII quality. So if you say "auto foo  
 = 1"
 is much like "static bar = 1", you are mistaken. The 2nd one doesn't  
 cause
 it to be non-static, so why does the 1st make it non-RAII?

 If auto for implicit type inference stays, I propose removing it for  
 RAII
 in declarations. If you want RAII you can simply use scope(exit) delete
 baz; after the declaration.
Sorry, why to do that? I don't want to be forced to free every object manually with scope(exit)? Then it wouldn't be RAII anymore! Or I don't understand your point.
They accomplish the same thing, but perhaps scope can be used to indicate RAII: scope(raii) Foo f = new Foo; or scope(auto) etc
Mar 14 2006
parent reply Tom <Tom_member pathlink.com> writes:
In article <op.s6fkcmh7po9bzi moe>, Chris Miller says...
On Mon, 13 Mar 2006 10:02:49 -0500, Tom <Tom_member pathlink.com> wrote:

 In article <dv3u5j$2ot1$1 digitaldaemon.com>, Jarrett Billingsley says...
 "Chris Miller" <chris dprogramming.com> wrote in message
 news:op.s6csodzipo9bzi moe...
 There is a problem with auto when declaring variables!

 Not only does it have 2 meanings, but when using it for implicit type
 inference, it no longer has the RAII quality. So if you say "auto foo  
 = 1"
 is much like "static bar = 1", you are mistaken. The 2nd one doesn't  
 cause
 it to be non-static, so why does the 1st make it non-RAII?

 If auto for implicit type inference stays, I propose removing it for  
 RAII
 in declarations. If you want RAII you can simply use scope(exit) delete
 baz; after the declaration.
Sorry, why to do that? I don't want to be forced to free every object manually with scope(exit)? Then it wouldn't be RAII anymore! Or I don't understand your point.
They accomplish the same thing, but perhaps scope can be used to indicate RAII: scope(raii) Foo f = new Foo; or scope(auto) etc
Oh I see. But to be obliged to add 'scope(exit) delete foo' after every RAII declaration isn't nice at all (though it is actually possible as an alternative to 'auto'). I think I'd prefer replace RAII-'auto' for the keyword 'local' since that keyword is straightforward to what it means. And now it comes to me the question: why is so important to have implicit type inference? Tom;
Mar 14 2006
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Tom wrote:
 In article <op.s6fkcmh7po9bzi moe>, Chris Miller says...
<snip>
 They accomplish the same thing, but perhaps scope can be used to indicate  
 RAII:
    scope(raii) Foo f = new Foo;
 or scope(auto)
 etc
<snip> Scope statements themselves create a scope, judging by analogy with other statements and the lack of any information to the contrary. It would seem a little strange to make scope(raii) an exception.... Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 15 2006
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Chris Miller wrote:
 There is a problem with auto when declaring variables!
 
 Not only does it have 2 meanings, but when using it for implicit type 
 inference, it no longer has the RAII quality. So if you say "auto foo = 
 1" is much like "static bar = 1", you are mistaken. The 2nd one doesn't 
 cause it to be non-static, so why does the 1st make it non-RAII?
 
 If auto for implicit type inference stays, I propose removing it for 
 RAII in declarations.
The RAII meaning of auto came first. D programmers from pre-0.137 days are going to be confused when they discover that auto has nothing in common with its old self.
 If you want RAII you can simply use scope(exit) 
 delete baz; after the declaration. Also, the "auto class {}" form can 
 still stay since it is in unrelated code and there is no easy 
 replacement for it.
OK, so it will still have this in common. But the way the auto keyword is overloaded will look no less a mess. If we're going to change the auto keyword, we should change at least one of its meanings to be denoted by a whole new keyword. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Mar 15 2006