Learn Coding Naming conventions - aliconnect/aliconnect.sdk GitHub Wiki
Coding Naming conventions
Introductie
Requirements
- Redability: At least one study found that readers can recognize snake case values more quickly than camelCase.
- Compatibility: Languages as PHP, SQL or ST are case insensitive for classes, methods and functions unlike JavaScript. To be multi platform compatible we use snake case for classes and operations.
Convention guideline
- Classes: UpperCamelCase
- Class names should be nouns in UpperCamelCase, with the first letter of every word capitalised. Use whole words — avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as
URL
orHTML
). - Recommended by .NET, PHP, Python, Ruby and many others.
- Examples:
class Raster {}
,class ImageSprite {}
- Class names should be nouns in UpperCamelCase, with the first letter of every word capitalised. Use whole words — avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as
- Identifiers: UpperCamelCase
- An identifier is a name that identifies (that is, labels the identity of) either a unique object or a unique class of objects, where the "object" or class may be an idea, physical [countable] object (or class thereof), or physical [noncountable] substance (or class thereof). The abbreviation ID often refers to identity, identification (the process of identifying), or an identifier (that is, an instance of identification). An identifier may be a word, number, letter, symbol, or any combination of those.
- Methods and Functionnames: lowerCamelCase
- Methods should be verbs in lowerCamelCase or a multi-word name that begins with a verb in lowercase; that is, with the first letter lowercase and the first letters of subsequent words in uppercase.
- Examples:
run();
,runFast();
,getBackground();
- Parameters: lowerCamelCase
- Variables: lowerCamelCase
- Local variables, instance variables, and class variables are also written in lowerCamelCase.
- Variable names should not start with underscore (
_
) or dollar sign ($
) characters, even though both are allowed. This is in contrast to other coding conventions that state that underscores should be used to prefix all instance variables. - Variable names should be short yet meaningful. The choice of a variable name should be mnemonic — that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables.
- Commonly recommended by companies such as Microsoft is that no type prefix hints (also known as Hungarian notation) are used.
- Instead of using Hungarian notation it is recommended to end the name with the base class name;
LoginButton
instead ofBtnLogin
- Common names for temporary variables are
i
,j
,k
,m
, andn
for integers;c
,d
, ande
for characters. - Examples:
int i;
,char c;
,float myWidth;
- Constants: MACRO_CASE
- Constants should be written in uppercase characters separated by underscores. Constant names may also contain digits if appropriate, but not as the first character.
- for C and C++ constants are mostly defined as all-upper-case. These are hard to handle in languages as ST. This convention is not recommended;
- Constants such as
__reserved
or_Reserved
should not be used. Prefixing and suffixing with double underscores are reserved for "magic names". - Examples:
static final int MAX_PARTICIPANTS = 10;
- Keywords: snake_case
- keyword and other names thould be snake_case
- Recommended by .NET, PHP, Python, Ruby and many others.
- Standard library identifiers: snake_case
- Standard libraries often uses an underscore as a word separator (e.g.
out_of_range
).
- Standard libraries often uses an underscore as a word separator (e.g.
While some dialects support underscore and dollar signs in identifiers, snake case and macro case is more likely confined to use within foreign API interfaces
- property type object: UpperCamelCase
- property type array: lowerCamelCase
- property type string: lowerCamelCase
- property type number: lowerCamelCase