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. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
that recommend programming style, practices, and methods for each aspect of a program written in that language. These conventions usually cover file organization, indentation, comments, declarations, statements, white space,
naming conventions A naming convention is a 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 instance, in Manhatta ...
, programming practices,
programming principles Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Programm ...
, 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. In natural language, the readability of text depends on its content (the complexity of its vocabulary and syntax) and its presentation (such as typographic aspects that ...
of their
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the ...
and make
software maintenance Software maintenance in software engineering is the modification of a software product after delivery to correct faults, to improve performance or other attributes. A common perception of maintenance is that it merely involves fixing defects. H ...
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 ( peers). It functions as a form of self-regulation by qualified members of a profession within the relevant field. Peer revie ...
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 translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
s.


Software maintenance

Reducing the cost of
software maintenance Software maintenance in software engineering is the modification of a software product after delivery to correct faults, to improve performance or other attributes. A common perception of maintenance is that it merely involves fixing defects. H ...
is the most often cited reason for following coding conventions. In their introduction to code conventions for the Java programming language, Sun Microsystems provides the following rationale:
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 author's colleagues, in order to evaluate the work product's technical content and quality. Purpose The purpose ...
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 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 computer code—changing the '' factoring''—without changing its external behavior. Refactoring is intended to improve the design, structu ...
refers to a software maintenance activity where
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the ...
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 functions) 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 is a process of dividing software development work into smaller, parallel, or sequential steps or sub-processes to improve design, product management. It is also known as a software deve ...
.


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) 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 a programmer-readable explanation or ''annotation'' in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally i ...
s are often used to process documentation, two notable examples are
javadoc Javadoc (originally cased JavaDoc) is a documentation generator created by Sun Microsystems for the Java language (now owned by Oracle Corporation) for generating API documentation in HTML format from Java source code. The HTML format is used for ...
and
doxygen Doxygen ( ) is a documentation generator and static analysis tool for software source trees. When used as a documentation generator, Doxygen extracts information from specially-formatted comments within the code. When used for analysis, Doxyge ...
. 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 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 "safe", the condition 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 There are two slightly di ...
and
security" \n\n\nsecurity.txt is a proposed standard for websites' security information that is meant to allow security researchers to easily report security vulnerabilities. The standard prescribes a text file called \"security.txt\" in the well known locat ...
), 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 and frequently among many
directories Directory may refer to: * Directory (computing), or folder, a file system structure in which to store computer files * Directory (OpenVMS command) * Directory service, a software application for organizing information about a computer network's ...
. 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, derived from imperative programming, based on the concept of the '' procedure call''. Procedures (a type of routine or subroutine) simply contain a series of computational steps to be carrie ...
(such as found in FORTRAN) towards more
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
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, 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. 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 Programming style, also known as code style, is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers read and understand sour ...
'' for numerous examples and discussion. Common coding conventions may cover the following areas: *
Comment Comment may refer to: * Comment (linguistics) or rheme, that which is said about the topic (theme) of a sentence * Bernard Comment (born 1960), Swiss writer and publisher Computing * Comment (computer programming), explanatory text or informat ...
conventions *
Indent style In computer programming, an indentation style is a convention governing the indentation of blocks of code to convey program structure. This article largely addresses the free-form languages, such as C and its descendants, but can be (and oft ...
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 t ...
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 wh ...
conventions * Programming practices *
Programming principles Program, programme, programmer, or programming may refer to: Business and management * Program management, the process of managing several related projects * Time management * Program, a part of planning Arts and entertainment Audio * Programm ...
* Programming style conventions Coding standards include the
CERT C Coding Standard The SEI CERT Coding Standards are software coding standards developed by the CERT Coordination Center to improve the safety, reliability, and security of software systems. Individual standards are offered for C, C++, Java, Android OS, and Perl. ...
, MISRA C, High Integrity C++, see list below.


Tool Support

There exists tools to help developers deal with coding conventions. Linters are able to find violations of conventions, pretty-printers enforce them at a massive scale. Research is also done to automatically fix coding convention errors.


List of coding standards


Coding conventions for languages

*ActionScript
Flex SDK coding conventions and best practices
*Ada

*Ada: [https://www.researchgate.net/publication/234821111_Guidance_for_the_use_of_the_Ada_programming_language_in_high_integrity_systems Guide for the use of the Ada programming language in high integrity systems] (ISO/IEC TR 15942:2000) *Ada
NASA Flight Software Branch — Ada Coding Standard
*Ada
ESA Ada Coding Standard - BSSC(98)3 Issue 1 October 1998
*Ada

*C:
CERT C Coding Standard The SEI CERT Coding Standards are software coding standards developed by the CERT Coordination Center to improve the safety, reliability, and security of software systems. Individual standards are offered for C, C++, Java, Android OS, and Perl. ...
br>CERT C Coding Standard
(SEI) *C
Embedded C Coding Standard
(Barr Group) *C
Firmware Development Standard
(Jack Ganssle) *C: MISRA C *C: TIOBE C Standard *C++
C++ Core Guidelines
(
Bjarne Stroustrup Bjarne Stroustrup (; ; born 30 December 1950) is a Danish computer scientist, most notable for the invention and development of the C++ programming language. As of July 2022, Stroustrup is a professor of Computer Science at Columbia University ...
,
Herb Sutter Herb Sutter is a prominent C++ expert. He is also a book author and was a columnist for Dr. Dobb's Journal. He joined Microsoft in 2002 as a platform evangelist for Visual C++ .NET, rising to lead software architect for C++/CLI. Sutter has serv ...
) *C++
Quantum Leaps C/C++ Coding Standard
*C++: C++ Programming/Programming Languages/C++/Code/Style Conventions *C++
GeoSoft's C++ Programming Style Guidelines
*C++

*C++: High Integrity C++ *C++
MISRA C++
*C++: Philips Healthcare C++ Coding Standard *C/C++
C/C++ Coding Guidelines
from devolo *C#
C# Coding Conventions (C# Programming Guide)
*C#
Design Guidelines for Developing Class Libraries
*C#
Brad Abrams
*C#
Philips Healthcare
or Philips Healthcare C# Coding Standard *D

*Dart
The Dart Style Guide
*Erlang
Erlang Programming Rules and Conventions
*Flex
Code conventions for the Flex SDK
*Java

*Java

(Not actively maintained. Latest version: 1999-APR-20.) *Java

*Java: *Java: TIOBE Java Standard *Java
SoftwareMonkey's coding conventions for Java and other brace-syntax languages
*JavaScript

*Lisp
Riastradh's Lisp Style Rules
*MATLAB
Neurobat Coding Conventions for MATLAB
*Object Pascal
Object Pascal Style Guide
*Perl

*PHP::PEAR
PHP::PEAR Coding Standards
*PHP::FIG
PHP Framework Interop Group
*PL/I

*Python

*R
The tidyverse style guide
*Ruby
The Unofficial Ruby Usage Guide
*Ruby
GitHub Ruby style guide
*Shell
Google's Shell Style Guide


Coding conventions for projects


Drupal PHP Coding Standards
* GNU Coding Standards *{{cite web , title = GNAT Coding Style: A Guide for GNAT Developers , work = GCC online documentation , publisher = Free Software Foundation , url = https://gcc.gnu.org/onlinedocs/gnat-style/ , accessdate = 2009-01-19
PDF

Linux Kernel Coding Style
(or Documentation/CodingStyle in the Linux Kernel source tree)
Mozilla Coding Style Guide
*Mono
Programming style for MonoOpenBSD Kernel source file style guide (KNF)Road Intranet's C++ GuidelinesStyle guides for Google-originated open-source projectsThe NetBSD source code style guide
(formerly known as the BSD Kernel Normal Form)
ZeroMQ C Language Style for Scalability (CLASS)


See also

* Comparison of programming languages (syntax) *
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, and in some dialects its type. The original Hungarian notation uses intention or kind in ...
*
Indent style In computer programming, an indentation style is a convention governing the indentation of blocks of code to convey program structure. This article largely addresses the free-form languages, such as C and its descendants, but can be (and oft ...
* List of tools for static code analysis * List of software development philosophies * MISRA * Programming style * Software metrics *
Software quality In the context of software engineering, software quality refers to two related but distinct notions: * Software functional quality reflects how well it complies with or conforms to a given design, based on functional requirements or specificatio ...
* The Power of 10 Rules


References

Source code