Coding By Convention
   HOME

TheInfoList



OR:

Convention over configuration (also known as coding by convention) is a software
design paradigm The concept of design paradigms derives from the rather ambiguous idea of paradigm originating in the sociology of science, which carries at least two main meanings: * As models, archetypes, or quintessential examples of solutions to problems. A ' ...
used by
software framework In computer programming, a software framework is a software abstraction that provides generic functionality which developers can extend with custom code to create applications. It establishes a standard foundation for building and deploying soft ...
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 information which is likely to change, replacing it with abstractions that are less likely to change, or using data normalization which avoids r ...
(DRY) principles. The concept was introduced by
David Heinemeier Hansson David Heinemeier Hansson, also known by his initials DHH, is a Danish software engineer, programmer, writer, entrepreneur, and racing driver. He is the creator of Ruby on Rails, a web framework written in Ruby. He is also a partner and chief t ...
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 pa ...
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 a ...
, 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 eit ...
s" and the
principle of least astonishment In user interface design and software design, the principle of least astonishment (POLA), also known as principle of least surprise, proposes that a component of a system should behave in a way that most users will expect it to behave, and there ...
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 ...
. The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there is a
class Class, Classes, or The Class may refer to: Common uses not otherwise categorized * Class (biology), a taxonomic rank * Class (knowledge representation), a collection of individuals or objects * Class (philosophy), an analytical concept used d ...
Sales in the model, the corresponding
table Table may refer to: * Table (database), how the table data arrangement is used within the databases * Table (furniture), a piece of furniture with a flat surface and one or more legs * Table (information), a data arrangement with rows and column ...
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 file A configuration file, a.k.a. config file, is a computer file, file that stores computer data, data used to configure a software system such as an application software, application, a server (computing), server or an operating system. Some applic ...
s. 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 data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
configuration files to specify which modules the framework should load, which was common in many earlier frameworks.


Disadvantages

Disadvantages of the convention over configuration approach can occur due to conflicts with other software design principles, like the
Zen of Python The Zen of Python is a collection of 19 Coding conventions, "guiding principles" for writing computer programs that influence the design of the Python (programming language), Python programming language. Python code that aligns with these principl ...
's "explicit is better than implicit." A
software framework In computer programming, a software framework is a software abstraction that provides generic functionality which developers can extend with custom code to create applications. It establishes a standard foundation for building and deploying soft ...
based on convention over configuration often involves a
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging ...
with a limited set of constructs or an
inversion of control In software engineering, inversion of control (IoC) is a design principle in which custom-written portions of a computer program receive the flow of control from an external source (e.g. a framework). The term "inversion" is historical: a softw ...
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 computing, a library is a collection of resources that can be leveraged during software development to implement a computer program. Commonly, a library consists of executable code such as compiled functions and classes, or a library can ...
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 In computer programming, a programming idiom, code idiom or simply idiom is a code fragment having a semantic role which recurs frequently across software projects. It often expresses a special feature of a recurring construct in one or more pro ...
and configuration libraries with a
multilayered architecture In software engineering, multitier architecture (often referred to as ''n''-tier architecture) is a client–server architecture in which presentation, application processing and data management functions are physically separated. The most wide ...
.


Motivation

Some frameworks need multiple
configuration file A configuration file, a.k.a. config file, is a computer file, file that stores computer data, data used to configure a software system such as an application software, application, a server (computing), server or an operating system. Some applic ...
s, 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 reduction entered by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It is 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 or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
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 data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
configuration file and instead employed these very conventions, deviations from which can be indicated through the use of
Java annotation In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. Class (computer programming), Classes, Method (computer programming), methods, Variable (computer science), variables ...
s (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 eit ...
, and can be spotted more recently in the roots of
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
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 ob ...
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 ob ...
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
JavaBean 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 ob ...
s 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 This is a comparison of web frameworks for front-end web development that are reliant on JavaScript code for their behavior. General in ...
*
Convention over Code Convention may refer to: * Convention (norm), a custom or tradition, a standard of presentation or conduct ** Treaty, an agreement in international law ** Convention (political norm), uncodified legal or political tradition * Convention (meeting), ...
*
Markedness In linguistics and social sciences, markedness is the state of standing out as nontypical or divergent as opposed to regular or common. In a marked–unmarked relation, one term of an opposition is the broader, dominant one. The dominant defau ...
*
Rapid application development Rapid application development (RAD), also called rapid application building (RAB), is both a general term for adaptive software development approaches, and the name for James Martin's method of rapid development. In general, RAD approaches to ...


References

* * *


External links

* {{DEFAULTSORT:Convention Over Configuration Object-oriented programming Software design