A convention is a set of agreed, stipulated, or generally accepted norms. It typically helps common efficiency or understanding but is not required, as opposed to a strict standard or protocol. In programming, a typical kind of convention is the coding convention which stipulates how programmers should format and style their programs.
Here are some examples of conventions that affect programming:
- Coding style: how the source code is formatted (indentation & spacing, location of braces, ordering of methods/functions, etc.). This helps programmers to read and understand the code more quickly, find bugs more easily.
- File naming: some programs expect the files they process to be named a certain way. For example, the
ant
command assumes by default that the build file is namesbuild.xml
, which allow developers to omit the file name in the command line. - File structure: programmers are often used to particular way to organize the files, that depends on the language / technology. This allows to read / browse through an unknown code base more easily. Even compilers of some language may expect files to be organized by default in a conventional way. For example,
maven
expects source files to be in asrc
directory and binary files in atarget
directory. - Variable naming: some variables with given semantics are conventionally named. For example,
for
loop variable are usually namedi
,j
,k
, etc.; and Cartesian coordinates are usually namedx
,y
andz
.