Convention over configuration (also known as coding by convention) is a software
design paradigm
A design is a plan or specification for the construction of an object or system or for the implementation of an activity or process or the result of that plan or specification in the form of a prototype, product, or process. The verb ''to design'' ...
used by
software framework
In computer programming, a software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software. It provides a standard ...
s that attempts to decrease the number of decisions that a
developer using the framework is required to make without necessarily losing flexibility and
don't repeat yourself
"Don't repeat yourself" (DRY) is a principle of software development aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy.
The DRY principle is stated as "Every piece o ...
(DRY) principles.
The concept was introduced by
David Heinemeier Hansson to describe the philosophy of the
Ruby on Rails
Ruby on Rails (simplified as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web ...
web framework
A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build an ...
, but is related to earlier ideas like the concept of "sensible
default
Default may refer to:
Law
* Default (law), the failure to do something required by law
** Default (finance), failure to satisfy the terms of a loan obligation or failure to pay back a loan
** Default judgment, a binding judgment in favor of ei ...
s" and the
principle of least astonishment
The principle of least astonishment (POLA), aka principle of least surprise (alternatively a law or rule), applies to user interface and software design. It proposes that a component of a system should behave in a way that most users will expect it ...
in
user interface design
User interface (UI) design or user interface engineering is the design of user interfaces for machines and software, such as computers, home appliances, mobile devices, and other electronic devices, with the focus on maximizing usability and ...
.
The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there is a
class Sales in the model, the corresponding
table
Table may refer to:
* Table (furniture), a piece of furniture with a flat surface and one or more legs
* Table (landform), a flat area of land
* Table (information), a data arrangement with rows and columns
* Table (database), how the table data ...
in the database is called "sales" by default. It is only if one deviates from this convention, such as the table "product sales", that one needs to write code regarding these names.
When the convention implemented by the tool matches the desired behavior, it behaves as expected without having to write configuration files. Only when the desired behavior deviates from the implemented convention is explicit configuration required.
Ruby on Rails' use of the phrase is particularly focused on its default project file and directory structure, which prevent developers from having to write
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. ...
configuration files to specify which
modules the framework should load, which was common in many earlier frameworks.
Disadvantages of the convention over configuration approach can occur due to conflicts with other software design principles, like the
Zen of Python's "explicit is better than implicit." A
software framework
In computer programming, a software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software. It provides a standard ...
based on convention over configuration often involves a
domain-specific language with a limited set of constructs or an
inversion of control in which the developer can only affect behavior using a limited set of
hooks, both of which can make implementing behaviors not easily expressed by the provided conventions more difficult than when using a
software library
In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and sub ...
that does not try to decrease the number of decisions developers have to make or require inversion of control.
Other methods of decreasing the number of decisions a developer needs to make include
programming idioms and configuration libraries with a
multilayered architecture.
Motivation
Some frameworks need multiple configuration files, each with many settings. These provide information specific to each project, ranging from URLs to mappings between classes and database tables. Many configuration files with many parameters are often difficult to maintain.
For example, early versions of the Java persistence mapper
Hibernate
Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
mapped entities and their fields to the database by describing these relationships in XML files. Most of this information could have been revealed by conventionally mapping class names to the identically named
database
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases spa ...
tables and the fields to their columns, respectively. Later versions did away with the
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. ...
configuration file and instead employed these very conventions, deviations from which can be indicated through the use of
Java annotations (see JavaBeans specification, linked below).
Usage

Many modern frameworks use a ''convention over configuration'' approach.
The concept is older, however, dating back to the concept of a
default
Default may refer to:
Law
* Default (law), the failure to do something required by law
** Default (finance), failure to satisfy the terms of a loan obligation or failure to pay back a loan
** Default judgment, a binding judgment in favor of ei ...
, and can be spotted more recently in the roots of
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
libraries. For example, the
JavaBeans
In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1.
The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized obj ...
specification relies on it heavily. To quote the
JavaBeans
In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1.
The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized obj ...
specification 1.01:
[Sun (24 July 1997)]
JavaBeans specification
, section 1.4. "As a general rule we don't want to invent an enormous java.beans.everything class that people have to inherit from. Instead we'd like the JavaBeans runtimes to provide default behaviour for 'normal' objects, but to allow objects to override a given piece of default behaviour by inheriting from some specific java.beans.something interface."
See also
*
Comparison of web frameworks Two comparisons of web frameworks are available:
* Comparison of JavaScript-based web frameworks (front-end)
* Comparison of server-side web frameworks
This is a comparison of notable web frameworks, software used to build and deploy web applicat ...
*
Convention over Code Convention over Code is a design approach for programming languages where the conventional use of a feature is taken into consideration when defining the default semantics of the feature.
Similar to Convention over Configuration, if a keyword can b ...
References
*
*
*
External links
*
{{DEFAULTSORT:Convention Over Configuration
Object-oriented programming
Software design