guides:programstyle:indentation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
guides:programstyle:indentation [2020/07/24 12:24] – [Code in a Code Block] wikiadmin | guides:programstyle:indentation [2024/07/25 15:01] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== Code in a Code Block ===== | ===== Code in a Code Block ===== | ||
+ | Code inside of a code block, | ||
+ | |||
+ | Example of acceptable use: | ||
<code c++> | <code c++> | ||
int value; | int value; | ||
Line 29: | Line 32: | ||
cin >> value; | cin >> value; | ||
} | } | ||
+ | </ | ||
+ | |||
+ | Code should be indented by a standard amount. | ||
+ | |||
+ | Unacceptable Example: | ||
+ | <code c++> | ||
+ | int value; | ||
+ | |||
+ | int max, | ||
+ | min; | ||
+ | | ||
+ | int count = 0; | ||
+ | |||
+ | cin >> value; | ||
+ | max = value; | ||
+ | min = value; | ||
+ | |||
+ | while (cin) { | ||
+ | if (max < value) { | ||
+ | max = value; | ||
+ | } | ||
+ | |||
+ | if (min > value) { | ||
+ | min = value; | ||
+ | } | ||
+ | |||
+ | | ||
+ | cin >> value; | ||
+ | } | ||
</ | </ | ||
===== A single statement occupying multiple lines ===== | ===== A single statement occupying multiple lines ===== | ||
+ | |||
+ | A second use of indentation is to highlight a line of code which wraps past the maximum line limit. | ||
+ | |||
+ | In a long parameter list, break the line at the beginning of a parameter declaration and align the next parameter declaration with the first declaration on the line above it. | ||
+ | |||
+ | <code c++> | ||
+ | void FloodFill(int & worldArray[MAX_ROWS][MAX_COLUMNS], | ||
+ | int colSize, int fillColor, int backgroundColor, | ||
+ | int currentRow, int current column); | ||
+ | </ | ||
+ | |||
+ | When declaring multiple variables of a single type it is helpful to indent each new identifier, especially when variables are initialized in the same statement. | ||
+ | |||
+ | <code c++> | ||
+ | int rowSize = 10, | ||
+ | colSize = 20, | ||
+ | fillColor = 4, | ||
+ | backgroundColor = 7; | ||
+ | </ | ||
guides/programstyle/indentation.1595593479.txt.gz · Last modified: 2024/07/25 15:01 (external edit)