Convention over Configuration (CoC) — is a principle that states that a system or framework already has default configurations, allowing the developer to avoid writing/creating settings themselves. This significantly reduces the number of decisions that need to be made and decreases the time spent on configuration and development overall.
This approach first gained popularity thanks to the Ruby on Rails framework. At the core of Rails is the idea that most developers will perform similar tasks in similar ways. Therefore, Rails provides typical solutions, such as file structuring, naming of models, controllers, and databases. If the accepted conventions are followed, the system automatically configures many aspects of the application. For example, a model named Article will automatically correspond to the articles table in the database, without the need for additional configuration.
This frees the developer from routine configuration. Exceptional cases where customization is needed can be easily configured separately; however, the bulk of tasks can be completed faster by using predefined conventions.
Eliminating excessive configuration allows focusing on the logic of the program rather than on settings. This speeds up development and reduces the number of errors, as fewer configurations mean fewer places where a bug can occur. At the same time, this approach can also be found outside of Rails. Many modern frameworks and tools use a similar approach — from JavaScript libraries to infrastructure management systems.
CoC is one of the key approaches to simplifying the development process, where applications that adhere to established conventions require minimal configuration, and the developer gains more freedom to create functionality instead of working with minor settings.
Example of CoC (RoR)
Let's take a closer look at an example of CoC to understand where we save time and reduce the likelihood of bugs due to added custom code.
The developer creates a model – for example, the Article model in Rails.
Since Convention over Configuration implies the use of conventions, Rails automatically expects the table for this model to be named articles (the standard plural for English nouns).
Rails automatically connects this model to the articles table in the database, without the need for additional settings. If the convention fits, no additional configuration is necessary.
This approach frees from unnecessary configuration, as the system relies on typical settings.
In simple terms - the framework already has common configurations that do not need to be invented; you just need to follow the conventions for everything to work "out of the box".