Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Code Style

Discussion in 'Open Projects' started by Thundernerd, Oct 1, 2020.

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

    Thundernerd

    Joined:
    Jan 24, 2014
    Posts:
    20
    Hi there,

    With this thing going on and people happily opening pull requests I thought it might be good to have the community decide on a coding style. In my opinion it is very important to make sure everything looks the same so that when you're reading someone else's code, you still know where to look, and what everything means.

    My suggestion would be to start with the official Microsoft Naming Guidelines or maybe the Google Style Guide for C#. This doesn't cover everything though, like making things private by default, adding [SerializeField] when needing to edit it, adding a read-only property if it needs to be accessed outside of the defining class, or a writable property/public method to handle setting of the value.

    Either way, I strongly suggest that this is discussed to create a clean project. It is a learning experience after all!

    Cheers
     
  2. Thundernerd

    Thundernerd

    Joined:
    Jan 24, 2014
    Posts:
    20
  3. Siafu

    Siafu

    Joined:
    Oct 16, 2014
    Posts:
    6
    I vote for Googles C# Style but with tabs instead of 2 space. I also vote for [SerializeField] private for editor access when public is not necessary.
     
    GordonArber likes this.
  4. ChemaDmk

    ChemaDmk

    Unity Technologies

    Joined:
    Jan 14, 2020
    Posts:
    65
  5. MattMirrorfish

    MattMirrorfish

    Joined:
    Dec 8, 2013
    Posts:
    40
Thread Status:
Not open for further replies.