Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

When to start uppercase or lowercase

Discussion in 'Scripting' started by ThomasUnity, Nov 13, 2015.

Thread Status:
Not open for further replies.
  1. ThomasUnity

    ThomasUnity

    Joined:
    Jul 10, 2015
    Posts:
    17
    Hi,
    Is there some logic in the use of uppercase and lowercase in the script syntax?
    I think I learned it like this:
    - methods start with capitals, variables start with lowercase.
    - And when refering to an instance (gameObject), you start with lowercase, refering to a class start uppercase (GameObject)
    - Please correct me if I'm wrong.

    But why is in this line below, the L (Length) is capital but the p (position) is lowercase. They are both variables, right?

    Instantiate(prefabs[Random.Range(0,prefabs.Length)], newTransform.position)

    It's so annoying to do this wrong all the time...
     
  2. L-Tyrosine

    L-Tyrosine

    Joined:
    Apr 27, 2011
    Posts:
    305
  3. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Note though, .Net capitalize property names, Unity does not. That is why Length is capitalized, and position is not.
     
    Kiwasi likes this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This.

    Properties are half way between methods and variables. Unity and Unity developers have a habit of treating them more like variables. .NET and .NET developers tend to treat them more like methods.

    Unity land is generally less strict on pure encapsulation principles then .NET land. This is because Unity's serialisation system does not play very well with properties and encapsulated data. As a side effect of this it often makes sense to retractor a variable to a property, or vice versa. Having the names identical means you don't have to change the public API.

    On the other hand .NET land encourages strict encapsulation. To the point where there are no public variables, everything is accessed through a property. Thus there is never any need to change the public API.
     
    lordofduct and ThermalFusion like this.
  5. ThomasUnity

    ThomasUnity

    Joined:
    Jul 10, 2015
    Posts:
    17
    by the way, i 'm using javascript. I couldn't find the answer to my question on the page that L-tyrosyne sugested. Still confused...
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    You're using unityscript, and there's no real naming standards defined for it.

    You could apply the C# standards to it, which is what that article covers.

    If you want to understand the standards laid out throughout the unity API... that was covered by @BoredMormon. Unity doesn't capitalize it's properties, and instead follows a more 'javascript' standard (javascript does have a standard, unityscript does not), for the reasons BoredMormon stated.

    That all together is the answer.
     
Thread Status:
Not open for further replies.