Programming style |
Programming style (also called coding standards or code convention) is a term that describes conventions for writing source code in a certain programming language.
Programming style is often dependent on the actual choice of programming language one is writing in. C (programming language) style will vary from BASIC programming language style, and so on.
=Characteristics of style=
Good style, being a subjective matter, is difficult to concretely categorize; however, there are a number of general characteristics. With the advent of software that formats source code automatically, the focus on how source code looks should yield to a greater focus on naming, logic, and higher techniques. As a practical point, using a computer to format source code saves time, and it is possible to then enforce company-wide standards without religious debates.
==Appropriate variable names==
Appropriate choices for variable names is seen as the keystone for good style. Poorly-named variables make code harder to read and understand.
For example, consider the following Pseudocode snippet:
get a b c if a < 12 and b < 60 and c < 60 return true else return false
Because of the choice of variable names, the function of the code is difficult to work out. However, if the variable names are made more descriptive:
get hours minutes seconds if hours < 12 and minutes < 60 and seconds < 60 return true else return false
the code s intent is easier to discern, namely, Given a 24-hour time, true will be returned if it is in the morning and false otherwise.
==Indent style==
Indent style, in programming languages that use braces or indenting to delimit logical blocks of code, such as C, is also a key to good style. Using a logical and consistent indent style makes one s code more readable. Compare:
if (hours < 12 && minutes < 60 && seconds < 60) { return true; } else { return false; }
with something like
if(hours|
|