I’m convinced that implicitness leads to a higher WTF per Minute (WTFPM) in the long run.
Implicitness requires the coder to remember hidden details instead of having them clearly defined in the code. For example, can you tell me why we’re adding “10” here?
Exactly, that was the point. No one can tell what “10” represents except the person who wrote it, and that’s awful in my opinion. If you have a team of engineers working on a project, how can anyone possibly navigate the codebase with such ambiguity?
Instead of implicitly adding “10”, we can prevent future headaches by simply creating a clear variable for the bonus. In my view, relying too heavily on implicit behavior can cause confusion and make managing the codebase more difficult.
Tim Peters’ second point in The Zen of Python states, “Explicit is better than implicit,” and I couldn’t agree more.
Imagine a function that grants access to different parts of a system based on a user’s role. In this example, implicit behavior leads to confusion about which roles have which permissions, making the code difficult to maintain.
The access control is handled with hard-coded roles and magic strings like ‘none’, making it unclear and unmanageable as more roles are added. Permissions are scattered throughout the code, leading to confusion and maintenance issues for future developers.
Why Explicit is Better
-
Explicit Mapping: The
ROLE_PERMISSIONS
object clearly defines each role and its corresponding permissions. -
Clarity: By making permissions explicit, there’s no need for magic strings or conditionals scattered across the codebase.
-
Maintainability: Future roles or changes to permissions can be easily updated in one place.
In my opinion, “Explicit is better than implicit” is about choosing clear, direct code over concise but potentially ambiguous alternatives. This principle puts readability and maintainability first, even if it means writing slightly more verbose code.
By being explicit, the intentions behind the code are obvious, making it easier for any developer to understand and work with the codebase.