Convention over Configuration — Explained with Examples
Convention over Configuration is a paradigm that reduces decision-making by providing sensible defaults while still allowing explicit overrides when needed.
Convention over Configuration (CoC) is a design approach popularized by Ruby on Rails. It minimizes the number of decisions developers must make by establishing reasonable defaults. You only write configuration when your needs diverge from the convention.
Why CoC Matters
Configuration files grow exponentially with project complexity. Every setting is a decision that consumes developer attention. CoC eliminates boilerplate by saying “this is the default — change it only if you must.” This accelerates development and reduces decision fatigue.
Real-World Analogy
Renting a car: the convention is that the steering wheel is on the left, pedals are arranged the same way, and the gear shift is in the center. You don’t reconfigure these every time you rent. Most cars follow these conventions so you can drive immediately. You only configure the radio presets (unconventional choices).
Example: Convention over Configuration
# Without CoC — every detail must be configured
class MySQLConnection:
def __init__(self, host, port, user, password, database,
charset, timeout, pool_size, ssl):
# 9 parameters every time
pass
# Usage — lots of repetition
conn1 = MySQLConnection("localhost", 3306, "root", "pass", "app_db",
"utf8mb4", 30, 5, False)
conn2 = MySQLConnection("localhost", 3306, "root", "pass", "test_db",
"utf8mb4", 30, 5, False)# With CoC — sensible defaults
class MySQLConnection:
def __init__(self, database,
host="localhost", # convention: dev runs locally
port=3306, # convention: default MySQL port
user="root", # convention: default dev user
charset="utf8mb4", # convention: modern encoding
timeout=30, # sensible default
pool_size=5, # reasonable pool
ssl=False): # off in dev, on in prod
self.host = host
# ... assign all
# Usage — only configure what's different
conn1 = MySQLConnection("app_db")
conn2 = MySQLConnection("test_db")
# Need different host? Override only that
conn3 = MySQLConnection("prod_db", host="db.prod.example.com", ssl=True)Related Terms
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro