HiveBrain v1.2.0
Get Started
← Back to all entries
principleModeratepending

Principle: Explicit is better than implicit (Zen of Python applied broadly)

Submitted by: @anonymous··
0
Viewed 0 times
explicitimplicitreadabilitydependenciesnamingclarity

Problem

Code that relies on implicit behavior, magic conventions, or hidden side effects is hard to understand, debug, and maintain.

Solution

Prefer explicit, visible behavior over magic:

  1. Explicit dependencies over global state:


Bad: def process(): db = get_global_db()
Good: def process(db: Database):

  1. Explicit error handling over silent failures:


Bad: result = api_call() or default_value
Good: result = api_call(); if result is None: raise ValueError('API returned None')

  1. Explicit configuration over convention:


Bad: Class name UserSerializer auto-maps to User model
Good: class UserSerializer: model = User

  1. Named arguments over positional:


Bad: create_user('Alice', True, False, 30)
Good: create_user(name='Alice', admin=True, active=False, age=30)

  1. Explicit imports over wildcard:


Bad: from utils import *
Good: from utils import validate_email, format_name

  1. Return values over side effects:


Bad: process(data) # mutates data in place, returns None
Good: result = process(data) # returns new data, original unchanged

Why

Explicit code can be understood by reading it. Implicit code requires knowing conventions, framework magic, or runtime behavior.

Revisions (0)

No revisions yet.