"_" Before variable Names

Posted:
in Genius Bar edited January 2014
During my adventure in Cocoa programming I started reading some sample code from the internet, MacTech magazine, etc. Now in most or not all of the sample code, I see variables with names like "_centerPoint" or "_foo". What does the underscore mean in these variable names?

Comments

  • Reply 1 of 4
    thuh freakthuh freak Posts: 2,664member
    underscore ("_") is just another character, like 'c' or 's'. i use it in some of my global variables when i'm afraid of using common names, since the underscore is quite uncommon.
  • Reply 2 of 4
    I know its just a character. I just wanted to know if it had some special meaning.
  • Reply 3 of 4
    The underscore suggests that a variable is private: it's not direectly used outside the object itself.
  • Reply 4 of 4
    amorphamorph Posts: 7,112member
    Any name beginning with a single or double underscore is reserved by the implementor, according to the ANSI C standard. It's used by compiler/environment writers for internal functions and variables (or methods and attributes, if you prefer).



    Analogously (and, given the standard, a bit unfortunately), it's a common naming convention for things that the writer intends to be internal and/or private, i.e., not used outside the file or class that it's found in.
Sign In or Register to comment.