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. Dismiss Notice

Question Why MonoBehaviour.print() starts with a small letter?

Discussion in 'Scripting' started by redhuck, Sep 20, 2023.

  1. redhuck

    redhuck

    Joined:
    Jan 14, 2022
    Posts:
    6
    Hello,

    This should be a very basic issue but I'm quite curious.
    In Unity, My understanding is that a name of a method starts with a capital letter, for example MonoBehaviour.GetComponent(), MonoBehaviour.Destroy(), MonoBehaviour.ToString(), etc.

    But why MonoBehaviour.print() starts with a small letter p, not being MonoBehaviour.Print() but MonoBehaviour.print()?

    Thanks in advance....
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,329
    Maybe it's related to the fact that many languages have a basic "print" method to output to the console/output stream so it was likely put there to enable a short-form and familiar call i.e. printing the contents.

    In the end, it's just a call to "Debug.Log()"

    Originally Unity supported C#, Javascript and Boo too.

    The 100% actual reason; not sure. :)
     
    Bunny83 likes this.
  3. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    71
    ...and then there
    Unity.Mathematics.math
     
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,440
    Well that's also a compatibility thing I guess. The math library aims at compatibility with HLSL. The "print" method (which is just a less powerful wrapper of Debug.Log and depends on a MonoBehaviour instance) was most likely just added for the other languages back then. Specifically Boo which was / is a .NET language with a python-like syntax.

    The reason why they made the mathematics library lower case is explained here:
     
    spiney199, Yoreki and MelvMay like this.
  5. redhuck

    redhuck

    Joined:
    Jan 14, 2022
    Posts:
    6
    It makes sense.
    Thank you very much!
     
    MelvMay likes this.