Re: Coding style question

From: Amos Jeffries <squid3_at_treenet.co.nz>
Date: Tue, 21 Aug 2012 17:36:42 +1200

On 21/08/2012 5:08 p.m., Kinkie wrote:
> Hi all,
> as I'm refactoring things around (currently hacking protos.h to
> pieces), I often encounter constructs such as:
>
> .h file:
> #if OPTIONAL_FEATURE
> extern void someFunction();
> #endif
>
> .cc file:
> #if OPTIONAL_FEATURE
> void someFunction() {
> //code
> }
> #endif
>
> client code:
> #if OPTIONAL_FEATURE
> someFunction(arg);
> #endif
>
>
> I'm wondering if it wouldn't be more readable to transform this pattern into:
> .h file:
> extern void someFunction();
>
> .cc file:
> #if OPTIONAL_FEATURE
> void someFunction() {
> //code
> }
> #else
> void someFunction() {
> nop(); return;
> }
> #endif
>
> client code:
> someFunction(arg);
>
>
> The runtime cost would be negligible (if any), but it'd turn the code
> into much less of a spaghetti.
> What do you think?
>
>

Or slightly better:

.h file:
#if OPTIONAL_FEATURE
extern void someFunction();
#else
// #define someFunction() // NOP
// or:
// static inline someFunction() {/* NOP */}
#endif

.cc file:
#if OPTIONAL_FEATURE
void someFunction()
{
   //code
}
#endif

client code:
   someFunction(arg);

Amos
Received on Tue Aug 21 2012 - 05:36:53 MDT

This archive was generated by hypermail 2.2.0 : Tue Aug 21 2012 - 12:00:06 MDT