guides:programstyle:identifiers
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| guides:programstyle:identifiers [2020/07/24 11:18] – wikiadmin | guides:programstyle:identifiers [2022/08/02 11:59] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| Examples of acceptable use: | Examples of acceptable use: | ||
| <code c++> | <code c++> | ||
| - | | + | int price; |
| - | float costToConsumer; | + | float costToConsumer; |
| - | double numberOfCars; | + | double numberOfCars; |
| </ | </ | ||
| Examples of unacceptable use: | Examples of unacceptable use: | ||
| <code c++> | <code c++> | ||
| - | int size_of_house; | + | int size_of_house; |
| - | | + | double PAY_AMOUNT; |
| </ | </ | ||
| ==== Named Constants ==== | ==== Named Constants ==== | ||
| + | |||
| + | Named constants should be declared in all upper case letters, with the underscore seperating multiple words. | ||
| + | |||
| + | Examples of acceptable use: | ||
| + | <code c++> | ||
| + | const PI = 3.14149; | ||
| + | const size_t MAX_ARRAY_SIZE = 20; | ||
| + | const int NUMBER_OF_PEOPLE = 100; | ||
| + | const string INPUT_FILE_NAME = " | ||
| + | </ | ||
| + | |||
| + | Examples of unacceptable use: | ||
| + | <code c++> | ||
| + | const float Pi = 3.14; | ||
| + | const string fileName = " | ||
| + | const int NUMBEROFSTARS = 2000; | ||
| + | </ | ||
| ==== Functions ==== | ==== Functions ==== | ||
| - | ==== Classes | + | |
| + | Each word in a function name begins with an upper case letter. | ||
| + | |||
| + | Examples of acceptable use: | ||
| + | <code c++> | ||
| + | void Uppercase(string & word); | ||
| + | int NumberOfLetters(string word); | ||
| + | </ | ||
| + | |||
| + | Examples of unacceptable use: | ||
| + | <code c++> | ||
| + | string userinput(); | ||
| + | </ | ||
| + | ==== User Defined Types ==== | ||
| + | |||
| + | When declaring user defined types use camel caps but end the name with a T. | ||
| + | |||
| + | Examples of acceptable use: | ||
| + | <code c++> | ||
| + | class SpeciesT { | ||
| + | ... | ||
| + | }; | ||
| + | |||
| + | typedef unsigned char MonthT; | ||
| + | </ | ||
| + | |||
| + | Examples of unacceptable use: | ||
| + | <code c++> | ||
| + | struct Person{ | ||
| + | ... | ||
| + | }; | ||
| + | </ | ||
| ===== Meaningful Identifier Names ===== | ===== Meaningful Identifier Names ===== | ||
| One key to self documenting code is to make identifier names that makes the code more readable without comments. | One key to self documenting code is to make identifier names that makes the code more readable without comments. | ||
| + | |||
| + | Examples of acceptable use: | ||
| + | <code c++> | ||
| + | int sizeOfInput; | ||
| + | double totalWeight; | ||
| + | </ | ||
| + | |||
| + | Examples of unacceptable use: | ||
| + | <code c++> | ||
| + | int a; | ||
| + | float rotAng; | ||
| + | </ | ||
| + | |||
| + | One exception to this rule is for loop control variables which can be single letters, normally //i//, //j// .... | ||
| + | |||
guides/programstyle/identifiers.1595589535.txt.gz · Last modified: 2022/08/02 11:59 (external edit)