Prev: "Scoping" variables the middle of their "natural" scope - RAII - is it a good practice?
Next: "Scoping" variables the middle of their "natural" scope - RAII - is it a good practice?
From: ManicQin on 17 Jan 2010 02:11 Thank you guys, About the first example I gave, it wasn't an example for RAII , I just tried to explain what do I mean in re-scoping. But take Ronald's example: ScopedLocks. If I un-intentionally delete the scopes ("{}") I can harm the logical flow of the system, suddenly the mutex applies to the entire scope of the function and not only for the resources I tried to protect. If you take auto_ptr and ScopedLock you can see a difference between them (besides their purpose of course!) for example with auto_ptr (IMO) the block of code that it resides in only determines the life span of the auto_ptr (and by that the pointer that he holds). in ScopedLock the block of code that it resides in determines the block of code that it operates on. I just think that the "closing curly brackets" were given a new power and the question is: "does a small curly bracket is strong enough tool for the mission?" On a personal note, In the company that I am employed we use the "C++ is a better C" paradigm (we use classes!), from time to time I'm trying to introduce people to new concepts and usually I hit the brick wall of "And what if the next guy wont know what you did and how to work with it?" (which is a very reasonable argument) So each time I try to introduce a new concept I check to see how destructive is it and does it worth it. Thanks. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |