const - Naming constants in C++ -
i replacing #defines, instance #define num_slider_positions 5
constant variables. should maintain old naming like:
const unsigned int num_slider_positions = 5;
or should utilize more like:
const unsigned int knumsliderpositions = 5;
.
edit: post has been set on hold, anyway i'd sum answers:
other alternative using underscores separators using lower case letters:
const unsigned int num_slider_positions = 5;
constant identifier.
regarding utilize of prefix way of identifying constants , mutual options not using it, may not add together relevant information:
const unsigned int num_slider_positions = 5;
use "k" before name:
const unsigned int k_num_slider_positions = 5;
or declaring variable within class or namespace, in order avoid polluting global scope , providing more self-explanatory name:
namespace defaults // or "config", or "settings" or { const unsigned int num_slider_positions = 5; }
client code:
int slider_positions = defaults::num_slider_positions;
i replacing #defines constant variables.
kudos! :)
should maintain old naming like: [all-caps]
if coding conventions of project designate constants in all-caps, should (as spares effort). otherwise, should not (because confusing later, maintenance).
or should utilize more like: [bastardized hungarian convention]
this you. not add together weird letters constants, because when reading code - or writing - not care much constant (and if seek write them, compiler allow me know).
my (personal) selection utilize namespace providing context (instead of prefix), along these lines:
namespace defaults // or "config", or "settings" or { const unsigned int num_slider_positions = 5; }
client code:
int slider_positions = defaults::num_slider_positions;
i find superior alternative, because context more self-explanatory (than "k" in front end of it, or "g" or whatever else).
c++ const naming-conventions naming
No comments:
Post a Comment