-1

Like below standards:

Class name should start with C -> CSomeClass
Integers should have prefix i -> int iIndex;
Bool prefix b -> bool bIndex;
Const char * prefix szc -> char * szcIndex
Pointers with prefix p -> int *piIndex; 
Const should add prefix c -> const int ciIndex;
for global variables use prefix g_ -> const double g_pi = 3.1415926535897;
for private variables use prefix m_ -> class{ int m_x;};
for function arguments use prefix t_ -> SomeMethod(int t_x){m_x = t_x;}

Naming variables like this, is that a good idea or bad idea?

Prasaathviki
  • 1,049
  • 2
  • 11
  • 21
  • This is called Hungarian Notation, and it's covered pretty extensively in the question I'm about to link ... in particular, the accepted answer links to an article with a good discussion of Apps vs Systems Hungarian. – Useless Jun 06 '19 at 10:02
  • 1
    Whatever works for you and your team. – Max Vollmer Jun 06 '19 at 10:02
  • 1
    opinions differ. i prefer the names to be descriptive about what they are used for and not (just/primariyl) their type. – Darklighter Jun 06 '19 at 10:03
  • 1
    you dont want to have to modify each occurence of a variable name when for some reason its type changes, do you?. Though you have to do it if you use that notation, otherwise it does great harm and no good. Especially with `auto` this appears to be rather antique. – 463035818_is_not_a_number Jun 06 '19 at 10:09

1 Answers1

4

No it's horrible and you'll struggle to reach consensus with your colleagues.

There was a brief flirtation with Hungarian Notation in the 1990s (short and long form), but it's largely fallen by the wayside. It creates refactoring headaches when types are changed (in C++ it's difficult to rename variables automatically due to quirks in the grammar cf. Java where you can do it without error).

Use variable names that are descriptive; that's all. That and syntax highlighting that many editors provide obviate the need to do anything special with variables.

(Personally I use _m for member variables and _s for static "members"; that's for clarity when using vi in emergency situations on production servers. I also have a rule that mathematical notation overrides any other convention; will use c for the speed of light in a vacuum for example, and G for Newton's constant.)

Lastly, your value for pi is evil: see Does C++11, 14, 17 or 20 introduce a standard constant for pi?

Bathsheba
  • 220,365
  • 33
  • 331
  • 451
  • 1
    Suppose you have a `template struct S { using Value = Value1; }`. Which name would you use for `Value1`? I encounter this problem each time I want to make alias member types in a class template for template parameters and keep meaningful names for template parameters themselves (not just `T`). Ideally, I would put `Value` in both places, but I can't. – Evg Jun 06 '19 at 10:15