const - Naming constants in C++ -


I am replacing my #defines, for example #define NUM_SLIDER_POSITIONS 5 fixed variable Do I have to keep the old names:

  Constant unsigned full NUM_SLIDER_POSITIONS = 5;  

Or should I use something else:

  const unsigned int kNumSliderPositions = 5;  

.

Edit : The post has been stopped, but anyway I want to add your answers:

Other options using lower case letters The underscores will be used as a separator:

  const unsigned int num_slider_positions = 5;   Persistent identifier.   

Regarding the use of a prefix as a way to identify constants, the most common choices are not being used because it can not add relevant information:

  const unsigned int num_slider_positions = 5;  

Use a "c" before the name:

  const unsigned int k_num_slider_positions = 5; To give more self-explanatory names to avoid polluting the global scope, declare the variable within the class or nomenclature:  
 < Code> namespace default // or "config", or "settings" or something like that {code signed int num_slider_positions = 5; }  

Client Code:

  int slider_positiones = defaults :: num_slider_positions;  

I am replacing #defines for my constant variable.

Yash! Should I keep the old naming like: [All Caps]

If coding for your project specifies stability to conventions, caps, You should not (as you spell an effort) otherwise, you should not (because it will be misleading for later maintenance).

Or should I like something more: [Bastardied Hungary conference]

It is up to you to personally add me strange letters to my constellation I do not like, because when reading or writing a code - I do not care that they are continuous (and if I try to write them, the compiler will tell me).

  Use the namespace defaults // or "config"  

, or "settings" or something like that {const unsigned Int num_slider_positions = 5; }

Client Code:

  int slider_positiones = defaults :: num_slider_positions;  

I think this is a better option because the context is more self-explanatory (with "a" in front of it, or "jee" or whatever).


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -