HOME

TheInfoList



OR:

Coding conventions are a set of guidelines for a specific
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
that recommend
programming style Programming style, also known as coding style, are the conventions and patterns used in writing source code, resulting in a consistent and readable codebase. These conventions often encompass aspects such as indentation, naming conventions, cap ...
, practices, and methods for each aspect of a program written in that language. These conventions usually cover file organization,
indentation __FORCETOC__ In the written form of many languages, indentation describes empty space ( white space) used before or around text to signify an important aspect of the text such as: * Beginning of a paragraph * Hierarchy subordinate concept * Qu ...
, comments, declarations,
statements Statement or statements may refer to: Common uses *Statement (computer science), the smallest standalone element of an imperative programming language * Statement (logic and semantics), declarative sentence that is either true or false *Statement, ...
, white space,
naming conventions A naming convention is a convention (norm), convention (generally agreed scheme) for naming things. Conventions differ in their intents, which may include to: * Allow useful information to be deduced from the names based on regularities. For ins ...
, programming practices,
programming principles Program (American English; also Commonwealth English in terms of computer programming and related activities) or programme (Commonwealth English in all other meanings), programmer, or programming may refer to: Business and management * Program m ...
, programming rules of thumb, architectural best practices, etc. These are guidelines for software structural quality. Software programmers are highly recommended to follow these guidelines to help improve the
readability Readability is the ease with which a reader can understand a written text. The concept exists in both natural language and programming languages though in different forms. In natural language, the readability of text depends on its content ( ...
of their
source code In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer. Since a computer, at base, only ...
and make
software maintenance Software maintenance is the modification of software after delivery. Software maintenance is often considered lower skilled and less rewarding than new development. As such, it is a common target for outsourcing or offshoring. Usually, the tea ...
easier. Coding conventions are only applicable to the human maintainers and
peer review Peer review is the evaluation of work by one or more people with similar competencies as the producers of the work (:wiktionary:peer#Etymology 2, peers). It functions as a form of self-regulation by qualified members of a profession within the ...
ers of a software project. Conventions may be formalized in a documented set of rules that an entire team or company follows, or may be as informal as the habitual coding practices of an individual. Coding conventions are not enforced by
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
s.


Software maintenance

Reducing the cost of
software maintenance Software maintenance is the modification of software after delivery. Software maintenance is often considered lower skilled and less rewarding than new development. As such, it is a common target for outsourcing or offshoring. Usually, the tea ...
is the most often cited reason for following coding conventions. In the introductory section on code conventions for the Java programming language, Sun Microsystems offers the following reasoning:
Code conventions are important to programmers for a number of reasons: *40%–80% of the lifetime cost of a piece of software goes to maintenance. *Hardly any software is maintained for its whole life by the original author. *Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. *If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.


Quality

Software peer review In software development, peer review is a type of software review in which a work product (document, code, or other) is examined by the author's colleagues, in order to evaluate the work product's technical content and quality. Purpose The purpo ...
frequently involves reading source code. This type of peer review is primarily a defect detection activity. By definition, only the original author of a piece of code has read the source file before the code is submitted for review. Code that is written using consistent guidelines is easier for other reviewers to understand and assimilate, improving the efficacy of the defect detection process. Even for the original author, consistently coded software eases maintainability. There is no guarantee that an individual will remember the precise rationale for why a particular piece of code was written in a certain way long after the code was originally written. Coding conventions can help. Consistent use of
whitespace White space or whitespace may refer to: Technology * Whitespace characters, characters in computing that represent horizontal or vertical space * White spaces (radio), allocated but locally unused radio frequencies * TV White Space Database, a m ...
improves readability and reduces the time it takes to understand the software.


Coding standards

Where coding conventions have been specifically designed to produce high-quality code, and have then been formally adopted, they then become coding standards. Specific styles, irrespective of whether they are commonly adopted, do not automatically produce good quality code.


Reduction of complexity

Complexity is a factor going against security. The management of complexity includes the following basic principle: minimize the amount of code written during the project development. This prevents unnecessary work which prevents unnecessary cost, both upfront and downstream. This is simply because if there is less code, it is less work not only to create the application, but also to maintain it. Complexity is managed both at the design stage (how the project is architectured) and at the development stage (by having simpler code). If the coding is kept basic and simple then the complexity will be minimised. Very often this is keeping the coding as 'physical' as possible - coding in a manner that is very direct and not highly abstract. This produces optimal code that is easy to read and follow. Complexity can also be avoided simply by not using complicated tools for simple jobs. The more complex the code is the more likely it is to be buggy, the more difficult the bugs are to find and the more likely there are to be hidden bugs.


Refactoring

Refactoring In computer programming and software design, code refactoring is the process of restructuring existing source code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structure, ...
refers to a software maintenance activity where
source code In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer. Since a computer, at base, only ...
is modified to improve readability or improve its structure. Software is often refactored to bring it into conformance with a team's stated coding standards after its initial release. Any change that does not alter the behavior of the software can be considered refactoring. Common refactoring activities are changing variable names, renaming methods, moving methods or whole classes and breaking large methods (or
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-orie ...
s) into smaller ones. Agile software development methodologies plan for regular (or even continuous) refactoring making it an integral part of the team
software development process In software engineering, a software development process or software development life cycle (SDLC) is a process of planning and managing software development. It typically involves dividing software development work into smaller, parallel, or s ...
.


Task automation

Coding conventions allow programmers to have simple scripts or programs whose job is to process source code for some purpose other than compiling it into an executable. It is common practice to count the software size (
Source lines of code Source lines of code (SLOC), also known as lines of code (LOC), is a software metric used to measure the size of a computer program by counting the number of lines in the text of the program's source code. SLOC is typically used to predict the am ...
) to track current project progress or establish a baseline for future project estimates. Consistent coding standards can, in turn, make the measurements more consistent. Special tags within
source code comment In computer programming, a comment is text embedded in source code that a translator (compiler or interpreter) ignores. Generally, a comment is an annotation intended to make the code easier for a programmer to understand often explaining an ...
s are often used to process documentation, two notable examples are
javadoc Javadoc (also capitalized as JavaDoc or javadoc) is an API documentation generator for the Java programming language. Based on information in Java source code, Javadoc generates documentation formatted as HTML and other formats via extensions. ...
and
doxygen Doxygen ( ) is a documentation generator that works with many programming languages. It extracts information from specially-formatted source code comments and saves the information in one of various supported formats. Doxygen supports static ...
. The tools specify the use of a set of tags, but their use within a project is determined by convention. Coding conventions simplify writing new software whose job is to process existing software. Use of
static code analysis In computer science, static program analysis (also known as static analysis or static simulation) is the analysis of computer programs performed without executing them, in contrast with dynamic program analysis, which is performed on programs duri ...
has grown consistently since the 1950s. Some of the growth of this class of development tools stems from increased maturity and sophistication of the practitioners themselves (and the modern focus on
safety Safety is the state of being protected from harm or other danger. Safety can also refer to the control of recognized hazards in order to achieve an acceptable level of risk. Meanings The word 'safety' entered the English language in the 1 ...
and
security Security is protection from, or resilience against, potential harm (or other unwanted coercion). Beneficiaries (technically referents) of security may be persons and social groups, objects and institutions, ecosystems, or any other entity or ...
), but also from the nature of the languages themselves.


Language factors

All software practitioners must grapple with the problem of organizing and managing a large number of sometimes complex instructions. For all but the smallest software projects, source code (instructions) are partitioned into separate
files File or filing may refer to: Mechanical tools and processes * File (tool), a tool used to remove fine amounts of material from a workpiece. **Filing (metalworking), a material removal process in manufacturing ** Nail file, a tool used to gentl ...
and frequently among many directories. It was natural for programmers to collect closely related functions (behaviors) in the same file and to collect related files into directories. As software development shifted from purely
procedural programming Procedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as Function (computer programming), procedures (a.k.a. functions, subroutines) that call each o ...
(such as found in FORTRAN) towards more
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
constructs (such as found in C++), it became the practice to write the code for a single (public) class in a single file (the 'one class per file' convention). Java has gone one step further - the Java compiler returns an error if it finds more than one public class per file. A convention in one language may be a requirement in another. Language conventions also affect individual source files. Each compiler (or interpreter) used to process source code is unique. The rules a compiler applies to the source creates implicit standards. For example, Python code is much more consistently indented than, say Perl, because whitespace (indentation) is actually significant to the interpreter. Python does not use the brace syntax Perl uses to delimit functions. Changes in indentation serve as the delimiters.
Tcl TCL or Tcl or TCLs may refer to: Business * TCL Technology, a Chinese consumer electronics and appliance company ** TCL Electronics, a subsidiary of TCL Technology * Texas Collegiate League, a collegiate baseball league * Trade Centre Limited ...
, which uses a brace syntax similar to Perl or C/C++ to delimit functions, does not allow the following, which seems fairly reasonable to a C programmer: set i = 0 while The reason is that in Tcl, curly braces are not used only to delimit functions as in C or Java. More generally, curly braces are used to group words together into a single argument. {{cite web , last = Staplin , first = George Peter , title = Why can I not start a new line before a brace group , publisher = 'the Tcler's Wiki' , date = 2006-07-16 , url = http://wiki.tcl.tk/8344 In Tcl, the ''word'' while takes two arguments, a ''condition'' and an ''action''. In the example above, while is missing its second argument, its ''action'' (because the Tcl also uses the newline character to delimit the end of a command).


Common conventions

There are a large number of coding conventions; see '' Coding Style'' for numerous examples and discussion. Common coding conventions may cover the following areas: * Comment conventions *
Indent style In computer programming, indentation style is a convention or style, governing the indentation of lines of source code. An indentation style generally specifies a consistent number of whitespace characters before each line of a block, so that ...
conventions *
Line length In typography, line length is the width of a block of typeset text, usually measured in units of length like inches or points or in characters per line (in which case it is a measure). A block of text or paragraph has a maximum line length tha ...
conventions *
Naming Naming is assigning a name to something. Naming may refer to: * Naming (parliamentary procedure), a procedure in certain parliamentary bodies * Naming ceremony, an event at which an infant is named * Product naming, the discipline of deciding wha ...
conventions * Programming practices *
Programming principles Program (American English; also Commonwealth English in terms of computer programming and related activities) or programme (Commonwealth English in all other meanings), programmer, or programming may refer to: Business and management * Program m ...
*
Programming style Programming style, also known as coding style, are the conventions and patterns used in writing source code, resulting in a consistent and readable codebase. These conventions often encompass aspects such as indentation, naming conventions, cap ...
conventions Coding standards include the CERT C Coding Standard,
MISRA C MISRA C is a set of software development guidelines for the C (programming language), C programming language developed by Motor Industry Software Reliability Association, The MISRA Consortium. Its aims are to facilitate code safety, Computer secur ...
, High Integrity C++.


See also

*
Comparison of programming languages (syntax) This article compares the syntax of many notable programming languages. Expressions Programming language expressions can be broadly classified into four syntax structures: ;prefix notation * Lisp (* (+ 2 3) (expt 4 5)) ;infix notation * F ...
*
Hungarian Notation Hungarian notation is an identifier naming convention in computer programming in which the name of a variable or function indicates its intention or kind, or in some dialects, its type. The original Hungarian notation uses only intention or kin ...
*
Indent style In computer programming, indentation style is a convention or style, governing the indentation of lines of source code. An indentation style generally specifies a consistent number of whitespace characters before each line of a block, so that ...
*
List of tools for static code analysis This is a list of notable tools for static program analysis (program analysis is a synonym for code analysis). Static code analysis tools Languages Ada * * * * * * * * * C, C++ * * Axivion Suite (Bauhaus) * * * ...
*
List of software development philosophies This is a list of approaches, styles, methodologies, and philosophies in software development and engineering. It also contains programming paradigms, software development methodologies, software development processes, and single practices, prin ...
* MISRA *
Programming style Programming style, also known as coding style, are the conventions and patterns used in writing source code, resulting in a consistent and readable codebase. These conventions often encompass aspects such as indentation, naming conventions, cap ...
*
Software metrics In software engineering and Software development, development, a software metric is a standard of measure of a degree to which a software system or process possesses some property. Even if a metric is not a measurement (metrics are functions, whi ...
*
Software quality In the context of software engineering, software quality refers to two related but distinct notions: * Software's functional quality reflects how well it complies with or conforms to a given design, based on functional requirements or specificat ...
* The Power of 10 Rules


References

Source code