c++ - Seemingly pointless #define of function -


i've encountered code along lines of:

bool cblahclass::somefunction(dword *pdw) {     return_false_if_file_doesnt_exist      //the rest of code makes sense...     //... } 

everything see makes pretty sense except have little question line return_false_if_file_doesnt_exist

i searched string , find #define:

#define return_false_if_file_doesnt_exist \         if (false==doesfileexist()) return false; 

my question is... hell? there reason make #define this? why not write:

bool cblahclass::somefunction(dword *pdw) {     if ( false == doesfileexist() ) return false      //the rest of code makes sense...     //... } 

the reason can think of is little bit easier , little less annoying write out "return_false_if_file_doesnt_exist" write out "if (false==doesfileexist()) return false".

anyone see other reason this? there name sort of thing?

well, idea behind using macro simplify maintenance in situations when specific check might change. when have macro, have change macro definition, instead of crawling through whole program , changing each check individually. also, gives opportunity eliminate check changing macro definition.

in general, when 1 has well-rounded repetitive piece of code, 1 typically separates code function. however, when repetitive piece of code has perform unorthodox operation, return exits enclosing function, macros option. (one'd agree tricks should reserved debugging/maintenance/system-level code, , should avoided in application-level code.)


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -