due requirements changing , forth, have if/else blocks using consts in our code, exampe:
const bool displayaveragevalues = true; if(displayaveragevalue) { // } else { // }
since requirements might change again, don't want remove unused code - might needed next week. don't want comment out unused code, since want part of refactoring. should ready compilation @ time changing boolean value.
the problem warnings unreachable code, thinking replacing standard if/else-block preprocessor #if/#else.
#define displayaveragevalues #if displayaveragevalue // #else // #endif
the problem i'm facing preprocessor symbol can't set false, can defined or undefined. lot more obvious change from:
#define displayaveragevalues true
to
#define displayaveragevalues false
instead of
#undef displayaveragevalues
or
//#define displayaveragevalues
(which might cause trouble if same symbol name has been used elsewhere).
is there better way?
preprocessor dirrectives in case when have presice slices in code architecture, when 1 code has compilable , not intersecting other. in case, seems face different options, somehow may intersect in requirements along code execution flow.
in opinion, best way manage define options
, runtimeconfigurations
, or whatever else, class holds properties impact application runtime behavior, , pass instance (may singletone
) of class along parts of application has take in consideration different execution options.
another option daniel said, exracting code different modules, plugins if wish, , load them dynamically. may or may not possible implement, , way, need spend non irrelevant amount of time, generaly, achieve level of flexibility, if wasn't considered before in architecture.
Comments
Post a Comment