Kanda SDK 0.6.0
|
We base our guidelines on the Microsoft coding conventions: Microsoft Coding Conventions. There might be minor variations or clarifications, which are outlined here alongside general good practices.
Coding is design. The code reader is the target audience, so readability and understandability are paramount. Prioritize intelligibility, clarity, and transparency over cleverness.
The Kanda SDK packages use CSharpier to format the code. This ensures consistency, and reduces friction when merging branches.
The rules are left to the defaults, except for one:
PascalCase
_underscoreCamelCase
(even if they are [SerializedField]
)camelCase
PascalCase
IPascalCase
(prefixed with a capital “I”)PascalCase
(visible to derived classes)PascalCase
s_
(e.g., s_foo
)t_
(e.g., t_bar
)Effort in naming variables aids in understanding business logic at a glance. Follow these rules:
Too verbose is better than too short.
Purpose is better than data type.
Self-evident method behavior from name is better than comments.
Words are better than single letters.
It is okay to prefix a name with something absurd if it helps clarity, obviousness, self-evidence, or transparency.
Examples:
MethodWithUnsafeConversion_UNSAFE
.UninitializedClass
.ProcessVerifiedData(MyClass data)
wrapping ProcessData(MyClass data)
.Always use brackets for multiline statements.
Names should be self-explanatory and not need comments. When used, comments should explain the reasoning behind solutions:
Comments can help group sections or guide the reader’s eyes. Prioritize clean code and avoid checking in commented-out code.
We encourage keeping in mind the measurements of Cyclomatic Complexity.
Use the following score system:
For further information on Cyclomatic Complexity, see: Code Complexity and Clean Code.