Search Unity

Is there a recommended naming convention?

Discussion in 'Scripting' started by Neural Echo, Oct 25, 2007.

  1. Neural Echo

    Neural Echo

    Joined:
    Jul 5, 2007
    Posts:
    83
    As JavaScript is case sensitive, does anyone know if there is a recommended naming convention for variable, function and object (class) names?
     
  2. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    When I was new and looking at the examples, I easily got confused about what terms were built into Unity vs. what were variables or script names that could be anything. Maybe all-caps or all-lowercase would help avoid that.

    Other than that, I think whatever you find readable is best! The examples/tutorials might show what others have done.
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I've always seen class names being uppercase and members/variables being lowercase. lowercase class names confuse the hell out of me because I think they're variables.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, lowercase for variables and uppercase for class names and functions.

    --Eric
     
  5. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    In OO programming one very common approach is:
    • => ThisIsAClass
      => thisIsAFunction( )
      => thisIsAVariable
      => _thisIsAClassVariable
      => IThisIsAnInterface
    And exceptions usually have Exception in the end, e.g. IOException, FileNotExistentException.

    Can't recall of anything else right now.

    Regards,
    Afonso
     
  6. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    The convention I work to is:
    • Class
    • Function()
    • propertyOrLocalVariable
    • m_MemberVariable (because Unity automatically strips the m_ prefix)
    This is consistent with Unity's API.
     
  7. Neural Echo

    Neural Echo

    Joined:
    Jul 5, 2007
    Posts:
    83
    Thanks for everyone's replies.

    I think it's probably best to go with the Unity consistent convention.