On Tue, Aug 21, 2012 at 7:36 AM, Amos Jeffries <squid3_at_treenet.co.nz> wrote:
> 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);
If any, I'd go for static inline (or just inline, after all the
namespace is already polluted).
Is the cost of the extra function call worth the decreased readibility?
-- /kinkieReceived on Tue Aug 21 2012 - 06:19:51 MDT
This archive was generated by hypermail 2.2.0 : Tue Aug 21 2012 - 12:00:06 MDT