Barr Group TwitterBarr Group Vimeo

Rules:

3.1.a. Each of the keywords if, while, for, switch, and return shall be followed by one space when there is additional program text on the same line.

3.1.b. Each of the assignment operators =, +=, -=, *=, /=, %=, &=, |=, ^=, ~=, and !=shall always be preceded and followed by one space.

3.1.c. Each of the binary operators +, -, *, /, %, <, <=, >, >=, ==,!=, <<, >>, &, |, ^, &&, and || shall always be preceded and followed by one space.

3.1.d. Each of the unary operators +, -, ++, --, ! , and ~, shall be written without a space on the operand side.

3.1.e. The pointer operators * and & shall be written with white space on each side within declarations but otherwise without a space on the operand side.

3.1.f. The ? and : characters that comprise the ternary operator shall each always be preceded and followed by one space.

3.1.g. The structure pointer and structure member operators (-> and ., respectively) shall always be without surrounding spaces.

3.1.h. The left and right brackets of the array subscript operator ([ and ]) shall be without surrounding spaces, except as required by another white space rule.

3.1.i. Expressions within parentheses shall always have no spaces adjacent to the left and right parenthesis characters.

3.1.j. The left and right parentheses of the function call operator shall always be without surrounding spaces, except that the function declaration shall feature one space between the function name and the left parenthesis to allow that one particular mention of the function name to be easily located.

3.1.k. Except when at the end of a line, each comma separating function parameters shall always be followed by one space.

3.1.l. Each semicolon separating the elements of a statement shall always be followed by one space.

3.1.m. Each semicolon shall follow the statement it terminates without a preceding space.

Example: See Appendix D.

Reasoning: In source code, the placement of white space is as important as the placement of text. Good use of white space reduces eyestrain and increases the ability of programmers and reviewers of the code to spot potential bugs.

Enforcement: These rules shall be followed by programmers as they work as well as reinforced via a code beautifier, e.g., GNU Indent.

What’s happening and how it’s done. Get in the know.

Sign Up for Our Newsletter

Receive free how-to articles, industry news, and the latest info on Barr Group webinars and training courses via email. 

To prevent automated spam submissions leave this field empty.