Prev: warning: taking address of temporary, what's the problem?
Next: "Scoping" variables the middle of their "natural" scope - RAII - is it a good practice?
From: ManicQin on 16 Jan 2010 02:25 Hello everybody, Let me explain what I mean, In my job I find many times the next "pattern" void foo() { //some code { //"re-scoping" char sTmp[256] = ""; //some code } //some code } sometimes the "re-scoping" was made to keep sTmp in his reservation and sometimes it's just and old "if scope" that was deleted and the scopes were left on intention (or not by intention), my point is that dropping the scopes will -usually- wont harm the -logical- flow of the code. (it can cause compile problems because of redefinition but the code itself will be autonomous) When looking on projects and examples in the internet I find more and more "scoped" classes (RAII), ScopeGuard, ScopedTimer, ScopedBarrierEnd ,ScopedForking , auto_ptr (and his many friends) and the list is long... Now, when dropping the "re-scoping" of a class I can harm the - logical- flow of the code. (Well you can always add comments ... and hope someone will read them, or you can use macros such as #define SCOPETIMER_START(name) { ScopeTimer name(); #define SCOPETIMER_END } but I always find that using such macros to "ugly up" your code...) Is it a good practice to "re-scope"? (RAII classes) Are there any guide lines for RAII classes? thanks -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |