Code Principles πΒΆ
Use these principles when you change repository code, scripts, or automation. For organisational and team-process principles, see principles.md.
Principles πΒΆ
Follow these principles. Keep the rule column short, imperative, and as SMART as practical; use the reason column for the rationale, the principle column for the linked source name, and put the expanded wording in the details column.
Rule |
Reason |
Principle |
Details |
|---|---|---|---|
Consolidate duplicate logic before merging. |
Duplicate behavior is easier to keep consistent. |
Keep one implementation for each behavior and remove repeated logic from the touched files. |
|
Leave touched code cleaner than you found it. |
Small cleanup reduces future friction. |
Make small, safe cleanup improvements in the files you touch when they reduce friction without expanding the scope unnecessarily. |
|
Store each shared value once. |
Shared values drift when copied. |
Put shared fixed values in one canonical source and reference them everywhere else. |
|
Choose the simplest solution. |
Simple code is easier to change. |
Prefer the smallest implementation that still satisfies the requirement and remains easy to maintain. |
|
Give each module one reason to change. |
Focused modules are easier to test and replace. |
Each module, class, or function MUST have exactly one responsibility so that changes to one concern do not ripple into unrelated code. |
|
Build only what is needed now. |
Unused code adds maintenance burden without value. |
Do not implement functionality until it is required. Avoid speculative abstractions, optional hooks, and future-proofing that no current requirement justifies. |
|
Make prompts SMART. |
Clear prompts reduce ambiguity. |
Write prompts that are specific, measurable, achievable, relevant, and time-bound so the agent can act on them without ambiguity. |
|
Write the failing test first. |
Failing tests confirm requirements first. |
Start with a failing test, implement the minimum code, and refactor with confidence. |
|
Prefer beautiful code. |
Readable code is easier to trust. |
Choose code that is clean, coherent, and pleasant to read instead of code that is only clever. |
|
Prefer explicit behavior. |
Explicit behavior is easier to reason about. |
Make behavior visible in the code instead of relying on hidden assumptions. |
|
Mark intentional exceptions. |
Exceptions need context. |
Document intentional exceptions close to the relevant code so they stay visible until they can be removed. |
|
Prefer simple code. |
Simple code changes more safely. |
Choose the simplest solution that still does the job. |
|
Prefer manageable complexity. |
Controlled complexity keeps maintenance cost down. |
Keep complexity under control instead of making the solution more complicated than needed. |
|
Prefer flat structures. |
Shallow structures are easier to scan. |
Keep control flow and data structures shallow when a flatter shape works. |
|
Prefer sparse structures. |
Sparse layouts make intent clearer. |
Avoid dense packing when a clearer, more spacious layout improves understanding. |
|
Make code readable. |
Readable code speeds review and debugging. |
Write code so the next person can understand it quickly. |
|
Protect the rules from exceptions. |
Contained exceptions keep rules useful. |
Handle special cases without breaking the general rule set. |
|
Prefer practical solutions. |
Practical code works in the real repo. |
Choose the option that works well in practice over one that is only theoretically pure. |
|
Fail loudly on errors. |
Hidden failures cause harder incidents later. |
Do not let unexpected errors disappear unnoticed. |
|
Silence errors only intentionally. |
Suppressed errors need justification. |
Suppress errors only when you can explain why that is safe. |
|
Refuse to guess in ambiguity. |
Clarification is safer than guessing. |
Stop and clarify when the inputs or intent are unclear. |
|
Choose one obvious way. |
One standard path lowers cognitive load. |
Prefer one clear, standard path over multiple equivalent ones. |
|
Make the obvious path obvious. |
The right choice should be easiest. |
Shape the code so the recommended approach is the easiest to see. |
|
Act now when action is due. |
Deferred work tends to grow. |
Do the needed work now instead of deferring it without reason. |
|
Wait rather than rush. |
Premature action can make the result worse. |
Pause when acting immediately would make the result worse. |
|
Keep hard code easy to explain. |
Hard-to-explain code often hides flaws. |
If the code is hard to explain, rework it before merging. |
|
Keep easy code easy to explain. |
Easy-to-explain code is usually sound. |
If the code is easy to explain, it is likely a good idea. |
|
Use namespaces generously. |
Namespaces prevent collisions in a large repo. |
Group names so they do not collide and remain easy to navigate. |
For code quality rules, see lint.md. For framework-specific guidance, see ansible.md and make.md.