-
Notifications
You must be signed in to change notification settings - Fork 2
Coding Style
A style guide for you to write a code for the project.
Our overarching goals are conciseness, readability and simplicity. Also, this guide is written to keep Unity in mind.
- Nomenclature
- Declarations
- Spacing
- Brace Style
- Switch Statements
- Language
- Copyright Statement
- Smiley Face
- Credit
On the whole, naming should follow C# standards.
Namespaces are all PascalCase, multiple words concatenated together, without hyphens ( - ) or underscores ( _ ). The exception to this rule are acronyms like GUI or HUD, which can be uppercase:
AVOID:
com.pandonga.vrgame.UI.timerPREFER:
Pandonga.VRGame.UI.TimerClasses and interfaces are written in PascalCase. For example MannaSlider.
Methods are written in PascalCase. For example MethodName().
All non-static fields are written camelCase. Per Unity convention, this includes public fields as well. Except for private.
For example:
public class MyClass {
public int publicField;
int packagePrivate;
private int _myPrivate;
protected int myProtected;
}AVOID:
private int myPrivateVariablePREFER:
private int _myPrivateVariableStatic fields are the exception and should be written in PascalCase:
public static int TheAnswer = 42;All properties are written in PascalCase. For example:
public int PageNumber {
get { return pageNumber; }
set { pageNumber = value; }
}Parameters are written in camelCase.
AVOID:
void DoSomething(Vector3 Location)PREFER:
void DoSomething(Vector3 location)Single character values are to be avoided except for temporary looping variables.
Actions are written in PascalCase. For example:
public event Action<int> ValueChanged;In code, acronyms should be treated as words. For example:
AVOID:
XMLHTTPRequest
String URL
findPostByIDPREFER:
XmlHttpRequest
String url
findPostByIdAccess level modifiers should be explicitly defined for classes, methods and member variables.
Prefer single declaration per line.
AVOID:
string username, twitterHandle;PREFER:
string username;
string twitterHandle;Exactly one class per source file, although inner classes are encouraged where scoping appropriate.
All interfaces should be prefaced with the letter I.
AVOID:
MannaSliderPREFER:
IMannaSliderSpacing is absolutely important for an easy read.
AVOID:
class Manna;
x = y+z;
Damage = damageArray[i +1];PREFER:
class Manna;
x = y + z;
Damage = damageArray[i+1];Indentation should be done using tabs, not spaces.
Lines should be no longer than 100 characters long.
There should be exactly one blank line between methods to aid in visual clarity and organization. Whitespace within methods should separate functionality, but having too many sections in a method often means you should refactor into several methods.
All braces get their own line as it is a C# convention:
AVOID:
class MyClass
{
void DoSomething()
{
if (someTest)
{
// ...
}
else
{
// ...
}
}
}PREFER:
class MyClass {
void DoSomething() {
if (someTest) {
// ...
} else {
// ...
}
}
}Conditional statements are always required to be enclosed with braces, irrespective of the number of lines required.
AVOID:
if (someTest)
doSomething();
if (someTest) doSomethingElse();PREFER:
if (someTest) {
DoSomething();
}
if (someTest){
DoSomethingElse();
}Switch-statements come with default case by default. If the default case is never reached, be sure to remove it.
AVOID:
switch (variable) {
case 1:
break;
case 2:
break;
default:
break;
}PREFER:
switch (variable) {
case 1:
break;
case 2:
break;
}Use US English spelling.
AVOID:
string colour = "red";PREFER:
string color = "red";The exception here is MonoBehaviour as that's what the class is actually called.
/*
* Copyright (c) Pandonga Creatives
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this documentation files, to deal restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so.
*/
This style guide is edited by kertaskids from Ray Wenderlich.
Bahana
Bayu
Ardiawan Bagus Harisa - Project Manager
Andrean Nugraha Fajero - Lead Programmer
License
If you are none of these stakeholders above, you are not allowed to have, copy, download, distribute, and sell for personal or commercial use.