What's the deal with variable prefixes

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • What's the deal with variable prefixes

      What's your oppinion on variable prefixes that tells which type the variable is?

      For example:
      int iNumber;
      double dPrice;

      Does it really add useful information or just clutter to the code? I mean, usually you don't use a variable too far away from it's definition (or is it declaration? I keep mixing those two words up), most advanced editors keep track of variable type for you and in worst case the c++ compiler will throw an error at you.

      And similarily, is C prefix to classes (ie "class CPrimitive {...};") needed for something? It's understandable why an interface would get a prefix, since it's technically a class anyway.
    • For types, I don't find them helpful at all and feel they tend to muddy up the code. In Visual Studio, you can simply hover over the variable and find out its type if you need to, but I can usually tell simply by the context in which it's used.

      The prefixes we do use are m_ for member variables, g_ for global variables, and s_ for static member variables. No prefix means it's a local variable. I've found this helpful and have adopted it for my own personal code as well.

      I almost never use prefixes for classes. The only exception is 'I' (as in IView) for an interface class, but I don't do that consistently.

      Remember, there are as many naming/bracing conventions as there are programmers. Use what feels right to you.

      -Rez
    • Rez is right - use prefixes to show scope, not type.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • I've found that with a typesafe language such as C++, it really doesn't add anything, but the scope denotation is quite useful in many places. I personally loathe the addition of "C" in front of class names. In my opinion, it adds useless text to every class that you make. I mean, can't one tell that it's a class if you're instantiating a variable that's not a primitive type? I don't see the need for a formal denotation of a class type here.
      Feel you safe and secure in the protection of your pants . . . but one day, one day there shall be a No Pants Day and that shall be the harbinger of your undoing . . .
    • Originally posted by Tarviathun
      I personally loathe the addition of "C" in front of class names. In my opinion, it adds useless text to every class that you make. I mean, can't one tell that it's a class if you're instantiating a variable that's not a primitive type? I don't see the need for a formal denotation of a class type here.


      Ugh, I completely agree. Every time I see 'C' in front of a class name, a little piece of me dies.

      -Rez