c++ - Is there a coding style that explicitly mentions parameter names in calls? -


when pass flags function, values visible in function call. programmer has values corresponding in function definition. means @ different location or start typing function call again ide hints show up.

// function definition in header file void foo(bool output = false, bool formatted = false, bool debug = false);  // function call, not intuitive values mean foo(true, false, true); 

is there coding technique approach problem? example, pseudo code more intuitive, isn't valid c++.

// function call explicit mention of flags should true foo(output, debug); 

i know there many options explicitly mentioning options, overhead of needed computation or syntax, using std::unordered_map of options. syntax overhead becomes less c++11 initializer lists. however, stick common practice if exists.

in c++11, use scoped enumerations:

foo(output::yes, formatted::no, debug::yes); 

(if you're stuck in past, can similar, less elegant, regular enumerations).

there's old-school method of combining single-bit flag values:

enum {     output    = 1 << 0,     formatted = 1 << 1,     debug     = 1 << 2 };  foo(output | debug); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -