Programming style is set of coding rules followed by all the programmers to write the code. When multiple programmers work on the same software project, they frequently need to work with the program code written by some other developer. This becomes tedious or at times impossible, if all developers do not follow some standard programming style to code the program.
An appropriate programming style includes using function and variable names relevant to the intended task, using well-placed indentation, commenting code for the convenience of reader and overall presentation of code. This makes the program code readable and understandable by all, which in turn makes debugging and error solving easier. Also, proper coding style helps ease the documentation and updation.
Coding Guidelines
Practice of coding style varies with organizations, operating systems and language of coding itself.
The following coding elements may be defined under coding guidelines of an organization:
● Naming conventions – This section defines how to name functions, variables, constants and global variables.
● Indenting – This is the space left at the beginning of line, usually 2-8 whitespace or single tab.
● Whitespace – It is generally omitted at the end of line.
● Operators – Defines the rules of writing mathematical, assignment and logical operators. For example, assignment operator ‘=’ should have space before and after it, as in “x = 2”.
● Control Structures – The rules of writing if-then-else, case-switch, while-until and for control flow statements solely and in nested fashion.
● Line length and wrapping – Defines how many characters should be there in one line, mostly a line is 80 characters long. Wrapping defines how a line should be wrapped, if is too long.
● Functions – This defines how functions should be declared and invoked, with and without parameters.
● Variables – This mentions how variables of different data types are declared and defined.
● Comments – This is one of the important coding components, as the comments included in the code describe what the code actually does and all other associated descriptions. This section also helps creating help documentations for other developers.