OBEY Code Complete by Steve McConnell
Purpose
This repository follows Code Complete in the sense of Steve McConnell:
apply disciplined software construction practices that reduce defects, improve readability, and produce robust code under real-world constraints.
All code generation, edits, and reviews must optimize for:
- low-defect construction
- readable and intention-revealing code
- controlled complexity
- defensive programming where appropriate
- strong routine and class design
- practical correctness over style theater
This file is a binding engineering policy: MUST is binding, SHOULD is a strong default, and MUST NOT is forbidden.
Primary Directive
Construction quality is not accidental.
When uncertain, choose the option that:
- lowers defect probability
- makes the code easier to inspect and reason about
- reduces control-flow complexity
- uses data and routines clearly
- protects the program against invalid states and misuse
Do not optimize for cleverness, minimal keystrokes, or fashionable idioms at the cost of clarity.
Foundational Construction Rules
- Write code primarily for human readers.
- Favor clarity, locality, and explicitness over trickiness.
- Keep control flow simple and visible.
- Make correctness easier to achieve than incorrectness.
- Use conventions consistently.
Construction Prerequisites and Decisions
- Do not treat construction as isolated typing; verify that requirements, architecture, major risks, and coding conventions are clear enough for the change.
- Resolve major construction decisions before large implementation work: language constraints, error policy, data representation, reuse strategy, integration approach, and testing approach.
- Use upstream uncertainty as a reason to build a small validated slice, not as an excuse for speculative code.
- Keep the software metaphor or design model only if it helps make concrete construction decisions.
- Measure twice before cutting when an early decision will be expensive to reverse.
Pseudocode Programming Process
- For complex routines, sketch the routine in precise pseudocode or comments before filling in details.
- Refine pseudocode until it names the real steps at a consistent abstraction level.
- Convert clear pseudocode into code and keep only comments that still add intent, constraints, or rationale.
- Do not use pseudocode as a substitute for understanding the algorithm.
Routine Design Rules
- Routines should have one clear purpose.
- The routine name should describe the result or action precisely.
- Keep the interface as small as practical.
- Avoid long parameter lists and flag arguments.
- Separate setup, validation, computation, and side effects when they are conceptually different.
- Return values should be meaningful and hard to misuse.
- Prefer guard clauses and straightforward structure over deeply nested logic.
Anti-patterns (MUST NOT):
- routines that do several unrelated things
- routines whose names describe implementation detail instead of purpose
- many hidden side effects
- boolean parameters that switch routine mode
Variable and Data Rules
- Use names that reveal purpose and meaning.
- Keep variable scope as small as practical.
- Initialize variables deliberately.
- Prefer named constants or stable values where a variable is not meant to change.
- Avoid magic numbers and unexplained sentinel values.
- Use stronger data types when primitives hide meaning.
Anti-patterns (MUST NOT):
- reused loop/index/temp variables beyond their purpose
- long-lived mutable locals carrying many meanings
- values whose units or semantics are unclear
Data Type Rules
- Choose data types that make invalid or ambiguous values harder to represent.
- Name constants for magic values, units, bounds, and sentinel meanings.
- Use booleans only for true binary meanings; replace flag fields with clearer states when needed.
- Use enumerations or named alternatives when a value belongs to a closed set.
- Use arrays, records, maps, and tables only where their shape communicates the data meaning.
- Encapsulate unusual data structures behind routines or types that reveal purpose.
- Keep units, ranges, precision, encoding, and ownership visible near the data they affect.
Control Flow Rules
- Prefer the simplest control flow that expresses the logic.
- Keep nesting shallow when possible.
- Replace complicated boolean logic with named predicates or clearer structure.
- Use case/switch constructs only when they improve clarity.
- Eliminate impossible paths and dead branches.
- Avoid surprising exits unless they clarify the routine.
Anti-patterns (MUST NOT):
- deeply nested conditionals
- complicated loop exits with hidden state changes
- control flow dependent on side effects in expressions
- clever one-liners that obscure the logic
Statement, Conditional, and Loop Rules
- Organize straight-line code so dependencies appear before use and related statements stay together.
- Keep conditionals positive and direct when possible.
- Put the normal path where readers can find it quickly.
- Use loops with clear initialization, termination, and update rules.
- Keep loop bodies focused; extract work when a loop hides several responsibilities.
- Avoid unusual control structures unless they are clearer than ordinary alternatives.
- Use table-driven methods when repeated branching is stable and the table can be validated.
Defensive Programming Rules
- Validate inputs at trust boundaries.
- Use assertions or invariant checks where programmer assumptions matter.
- Distinguish between recoverable conditions and programming errors.
- Fail in a way that preserves diagnosability.
- Do not silently continue from corrupted or impossible state.
Anti-patterns (MUST NOT):
- assuming all callers are correct
- burying invalid state until it causes distant failures
- swallowing exceptions without context
Error Handling Rules
- Handle errors at the right level of abstraction.
- Preserve useful context.
- Do not let error handling dominate the normal path.
- Standardize similar failure handling.
- Prefer explicit, well-understood failure semantics over ad hoc conventions.
Table-Driven and Data-Driven Rules
- Prefer data-driven logic over long repeated condition chains when the mapping is stable and explicit.
- Use tables or maps for configuration-like decisions.
- Keep the structure obvious and validated.
- Do not hide complex logic in inscrutable data encodings.
Class and Module Design Rules
- Each class or module should own a focused responsibility.
- Separate interface from implementation.
- Hide representation and incidental detail.
- Keep classes cohesive.
- Reduce coupling through clear contracts and limited knowledge of internals.
Anti-patterns (MUST NOT):
- god classes
- modules with mixed persistence, formatting, business logic, and integration concerns
- public surfaces that expose internal bookkeeping
Complexity Management Rules
- Treat rising complexity as a defect risk.
- Prefer simple code over clever code.
- Break apart large or tangled routines and modules.
- Remove duplication that multiplies maintenance effort.
- Choose designs that reduce the amount a maintainer must keep in working memory.
Construction with Preconditions and Postconditions
- Be explicit about routine assumptions.
- Encode important invariants close to the code they protect.
- Keep contracts simple and testable.
- Use assertions for programmer mistakes, validation for external input, and domain errors for expected business failures.
Comment Rules
- Comments should explain intent, rationale, contracts, and non-obvious facts.
- Do not comment obvious code instead of improving it.
- Keep comments accurate or delete them.
- Prefer self-documenting structure first, comments second.
Coding Standards Rules
- Be consistent within the codebase.
- Use formatting, naming, and file structure to support readability.
- Standardize common idioms so readers do not need to relearn style per module.
- Prefer a shared convention over local personal taste.
Incremental Construction Rules
- Build in small, verifiable increments.
- Integrate frequently enough to surface conflicts and misunderstanding early.
- Keep partial work from rotting in long-lived isolation.
- Review and improve code as part of construction, not only after it.
Quality, Collaboration, Debugging, and Refactoring
- Use reviews, inspections, pair work, tests, and static checks according to the risk of the code.
- Treat debugging as diagnosis: reproduce, isolate, explain, fix, and verify rather than guessing.
- Fix the root cause when practical, not only the symptom.
- Add tests around defects so the same failure is easier to detect next time.
- Refactor when structure hides intent, duplicates knowledge, or raises defect probability.
- Keep refactoring separate from behavior changes when that improves reviewability.
Performance, Integration, Tools, and Craftsmanship
- Do not tune performance until the requirement and evidence justify it.
- When tuning is justified, measure before and after, and keep clarity unless the tradeoff is explicit.
- Integrate frequently enough to expose construction conflicts early.
- Use programming tools, scripts, debuggers, profilers, editors, and build automation to reduce error-prone manual work.
- Keep layout and style consistent enough that readers can focus on meaning.
- Prefer self-documenting code, but add documentation where the code cannot express intent, constraints, or usage.
- Treat personal discipline, curiosity, and ability to withstand careful review as part of construction quality.
Review Rules
When reviewing code, actively look for:
- unclear names
- weak routine boundaries
- long parameter lists
- unnecessary nesting
- hidden side effects
- poor defensive checks at trust boundaries
- duplicated logic
- confusing control flow
- god classes or mixed responsibilities
- comments compensating for poor structure
Forbidden Patterns
Cleverness over Clarity
- dense tricks that are hard to inspect
- compressed expressions that save lines but increase interpretation cost
Routine Bloat
- one routine doing several phases and concerns
- long signatures with many unrelated parameters
Defensive Vacuum
- no validation at trust boundaries
- no checks around critical assumptions
- silent fallback from impossible state
Comment-as-Crutch
- obvious comments over bad code
- stale comments that mislead
Consistency Neglect
- arbitrary naming and formatting changes
- module-specific mini dialects inside one codebase
Code Generation Rules
When generating code, default to:
- clear names
- focused routines
- explicit data meaning
- simple control flow
- defensive checks at boundaries
- cohesive classes/modules
- consistent style
Avoid by default:
- dense clever code
- broad god objects
- fragile hidden assumptions
- unnecessary complexity in loops and conditionals
- comments where better names or decomposition would do
Testing Rules
- Test routine behavior around normal, boundary, and invalid inputs.
- Test defensive checks where boundary validation matters.
- Keep tests aligned with routine contracts.
- Test complex data-driven logic with representative tables and edge cases.
Review Checklist
Before finalizing any change, verify:
- Are names clear and intention-revealing?
- Are routines focused and reasonably small?
- Is control flow straightforward?
- Are trust boundaries defended?
- Are contracts and invariants explicit enough?
- Did we reduce or at least not increase complexity?
- Are classes/modules cohesive?
- Did we avoid cleverness that harms inspection?
- Are comments used only where they add value?
- Is the style consistent with the rest of the codebase?
If any answer is no, revise before shipping.
Final Instruction
When uncertain, choose the option that:
- lowers defect risk
- improves readability
- simplifies control flow
- strengthens defensive correctness
- keeps the code easier to inspect and maintain
Write code that would stand up to careful review.
1---
2name: book-code-complete-full
3description: >-
4 Code Complete (Steve McConnell) — Full rules — comprehensive mandatory coding standards. Use when asked to apply Code Complete principles or review code against Code Complete standards.
5origin: "github.com/ciembor/agent-rules-books (MIT)"
6license: MIT
7version: "1.0.0"
8compatibility: "yana-ai >= 0.14.0"
9metadata:
10 source: https://skillmd.com/skills/yanacuti1121/book-code-complete-full
11---
12
13# OBEY Code Complete by Steve McConnell
14
15## Purpose
16
17This repository follows **Code Complete** in the sense of Steve McConnell:
18apply disciplined software construction practices that reduce defects, improve readability, and produce robust code under real-world constraints.
19
20All code generation, edits, and reviews must optimize for:
21- low-defect construction
22- readable and intention-revealing code
23- controlled complexity
24- defensive programming where appropriate
25- strong routine and class design
26- practical correctness over style theater
27
28This file is a binding engineering policy: `MUST` is binding, `SHOULD` is a strong default, and `MUST NOT` is forbidden.
29
30---
31
32## Primary Directive
33
34Construction quality is not accidental.
35
36When uncertain, choose the option that:
371. lowers defect probability
382. makes the code easier to inspect and reason about
393. reduces control-flow complexity
404. uses data and routines clearly
415. protects the program against invalid states and misuse
42
43Do not optimize for cleverness, minimal keystrokes, or fashionable idioms at the cost of clarity.
44
45---
46
47## Foundational Construction Rules
48
491. Write code primarily for human readers.
502. Favor clarity, locality, and explicitness over trickiness.
513. Keep control flow simple and visible.
524. Make correctness easier to achieve than incorrectness.
535. Use conventions consistently.
54
55---
56
57## Construction Prerequisites and Decisions
58
591. Do not treat construction as isolated typing; verify that requirements, architecture, major risks, and coding conventions are clear enough for the change.
602. Resolve major construction decisions before large implementation work: language constraints, error policy, data representation, reuse strategy, integration approach, and testing approach.
613. Use upstream uncertainty as a reason to build a small validated slice, not as an excuse for speculative code.
624. Keep the software metaphor or design model only if it helps make concrete construction decisions.
635. Measure twice before cutting when an early decision will be expensive to reverse.
64
65---
66
67## Pseudocode Programming Process
68
691. For complex routines, sketch the routine in precise pseudocode or comments before filling in details.
702. Refine pseudocode until it names the real steps at a consistent abstraction level.
713. Convert clear pseudocode into code and keep only comments that still add intent, constraints, or rationale.
724. Do not use pseudocode as a substitute for understanding the algorithm.
73
74---
75
76## Routine Design Rules
77
781. Routines should have one clear purpose.
792. The routine name should describe the result or action precisely.
803. Keep the interface as small as practical.
814. Avoid long parameter lists and flag arguments.
825. Separate setup, validation, computation, and side effects when they are conceptually different.
836. Return values should be meaningful and hard to misuse.
847. Prefer guard clauses and straightforward structure over deeply nested logic.
85
86Anti-patterns (MUST NOT):
87- routines that do several unrelated things
88- routines whose names describe implementation detail instead of purpose
89- many hidden side effects
90- boolean parameters that switch routine mode
91
92---
93
94## Variable and Data Rules
95
961. Use names that reveal purpose and meaning.
972. Keep variable scope as small as practical.
983. Initialize variables deliberately.
994. Prefer named constants or stable values where a variable is not meant to change.
1005. Avoid magic numbers and unexplained sentinel values.
1016. Use stronger data types when primitives hide meaning.
102
103Anti-patterns (MUST NOT):
104- reused loop/index/temp variables beyond their purpose
105- long-lived mutable locals carrying many meanings
106- values whose units or semantics are unclear
107
108---
109
110## Data Type Rules
111
1121. Choose data types that make invalid or ambiguous values harder to represent.
1132. Name constants for magic values, units, bounds, and sentinel meanings.
1143. Use booleans only for true binary meanings; replace flag fields with clearer states when needed.
1154. Use enumerations or named alternatives when a value belongs to a closed set.
1165. Use arrays, records, maps, and tables only where their shape communicates the data meaning.
1176. Encapsulate unusual data structures behind routines or types that reveal purpose.
1187. Keep units, ranges, precision, encoding, and ownership visible near the data they affect.
119
120---
121
122## Control Flow Rules
123
1241. Prefer the simplest control flow that expresses the logic.
1252. Keep nesting shallow when possible.
1263. Replace complicated boolean logic with named predicates or clearer structure.
1274. Use case/switch constructs only when they improve clarity.
1285. Eliminate impossible paths and dead branches.
1296. Avoid surprising exits unless they clarify the routine.
130
131Anti-patterns (MUST NOT):
132- deeply nested conditionals
133- complicated loop exits with hidden state changes
134- control flow dependent on side effects in expressions
135- clever one-liners that obscure the logic
136
137---
138
139## Statement, Conditional, and Loop Rules
140
1411. Organize straight-line code so dependencies appear before use and related statements stay together.
1422. Keep conditionals positive and direct when possible.
1433. Put the normal path where readers can find it quickly.
1444. Use loops with clear initialization, termination, and update rules.
1455. Keep loop bodies focused; extract work when a loop hides several responsibilities.
1466. Avoid unusual control structures unless they are clearer than ordinary alternatives.
1477. Use table-driven methods when repeated branching is stable and the table can be validated.
148
149---
150
151## Defensive Programming Rules
152
1531. Validate inputs at trust boundaries.
1542. Use assertions or invariant checks where programmer assumptions matter.
1553. Distinguish between recoverable conditions and programming errors.
1564. Fail in a way that preserves diagnosability.
1575. Do not silently continue from corrupted or impossible state.
158
159Anti-patterns (MUST NOT):
160- assuming all callers are correct
161- burying invalid state until it causes distant failures
162- swallowing exceptions without context
163
164---
165
166## Error Handling Rules
167
1681. Handle errors at the right level of abstraction.
1692. Preserve useful context.
1703. Do not let error handling dominate the normal path.
1714. Standardize similar failure handling.
1725. Prefer explicit, well-understood failure semantics over ad hoc conventions.
173
174---
175
176## Table-Driven and Data-Driven Rules
177
1781. Prefer data-driven logic over long repeated condition chains when the mapping is stable and explicit.
1792. Use tables or maps for configuration-like decisions.
1803. Keep the structure obvious and validated.
1814. Do not hide complex logic in inscrutable data encodings.
182
183---
184
185## Class and Module Design Rules
186
1871. Each class or module should own a focused responsibility.
1882. Separate interface from implementation.
1893. Hide representation and incidental detail.
1904. Keep classes cohesive.
1915. Reduce coupling through clear contracts and limited knowledge of internals.
192
193Anti-patterns (MUST NOT):
194- god classes
195- modules with mixed persistence, formatting, business logic, and integration concerns
196- public surfaces that expose internal bookkeeping
197
198---
199
200## Complexity Management Rules
201
2021. Treat rising complexity as a defect risk.
2032. Prefer simple code over clever code.
2043. Break apart large or tangled routines and modules.
2054. Remove duplication that multiplies maintenance effort.
2065. Choose designs that reduce the amount a maintainer must keep in working memory.
207
208---
209
210## Construction with Preconditions and Postconditions
211
2121. Be explicit about routine assumptions.
2132. Encode important invariants close to the code they protect.
2143. Keep contracts simple and testable.
2154. Use assertions for programmer mistakes, validation for external input, and domain errors for expected business failures.
216
217---
218
219## Comment Rules
220
2211. Comments should explain intent, rationale, contracts, and non-obvious facts.
2222. Do not comment obvious code instead of improving it.
2233. Keep comments accurate or delete them.
2244. Prefer self-documenting structure first, comments second.
225
226---
227
228## Coding Standards Rules
229
2301. Be consistent within the codebase.
2312. Use formatting, naming, and file structure to support readability.
2323. Standardize common idioms so readers do not need to relearn style per module.
2334. Prefer a shared convention over local personal taste.
234
235---
236
237## Incremental Construction Rules
238
2391. Build in small, verifiable increments.
2402. Integrate frequently enough to surface conflicts and misunderstanding early.
2413. Keep partial work from rotting in long-lived isolation.
2424. Review and improve code as part of construction, not only after it.
243
244---
245
246## Quality, Collaboration, Debugging, and Refactoring
247
2481. Use reviews, inspections, pair work, tests, and static checks according to the risk of the code.
2492. Treat debugging as diagnosis: reproduce, isolate, explain, fix, and verify rather than guessing.
2503. Fix the root cause when practical, not only the symptom.
2514. Add tests around defects so the same failure is easier to detect next time.
2525. Refactor when structure hides intent, duplicates knowledge, or raises defect probability.
2536. Keep refactoring separate from behavior changes when that improves reviewability.
254
255---
256
257## Performance, Integration, Tools, and Craftsmanship
258
2591. Do not tune performance until the requirement and evidence justify it.
2602. When tuning is justified, measure before and after, and keep clarity unless the tradeoff is explicit.
2613. Integrate frequently enough to expose construction conflicts early.
2624. Use programming tools, scripts, debuggers, profilers, editors, and build automation to reduce error-prone manual work.
2635. Keep layout and style consistent enough that readers can focus on meaning.
2646. Prefer self-documenting code, but add documentation where the code cannot express intent, constraints, or usage.
2657. Treat personal discipline, curiosity, and ability to withstand careful review as part of construction quality.
266
267---
268
269## Review Rules
270
271When reviewing code, actively look for:
272- unclear names
273- weak routine boundaries
274- long parameter lists
275- unnecessary nesting
276- hidden side effects
277- poor defensive checks at trust boundaries
278- duplicated logic
279- confusing control flow
280- god classes or mixed responsibilities
281- comments compensating for poor structure
282
283---
284
285## Forbidden Patterns
286
287### Cleverness over Clarity
288- dense tricks that are hard to inspect
289- compressed expressions that save lines but increase interpretation cost
290
291### Routine Bloat
292- one routine doing several phases and concerns
293- long signatures with many unrelated parameters
294
295### Defensive Vacuum
296- no validation at trust boundaries
297- no checks around critical assumptions
298- silent fallback from impossible state
299
300### Comment-as-Crutch
301- obvious comments over bad code
302- stale comments that mislead
303
304### Consistency Neglect
305- arbitrary naming and formatting changes
306- module-specific mini dialects inside one codebase
307
308---
309
310## Code Generation Rules
311
312When generating code, default to:
3131. clear names
3142. focused routines
3153. explicit data meaning
3164. simple control flow
3175. defensive checks at boundaries
3186. cohesive classes/modules
3197. consistent style
320
321Avoid by default:
322- dense clever code
323- broad god objects
324- fragile hidden assumptions
325- unnecessary complexity in loops and conditionals
326- comments where better names or decomposition would do
327
328---
329
330## Testing Rules
331
3321. Test routine behavior around normal, boundary, and invalid inputs.
3332. Test defensive checks where boundary validation matters.
3343. Keep tests aligned with routine contracts.
3354. Test complex data-driven logic with representative tables and edge cases.
336
337---
338
339## Review Checklist
340
341Before finalizing any change, verify:
342- Are names clear and intention-revealing?
343- Are routines focused and reasonably small?
344- Is control flow straightforward?
345- Are trust boundaries defended?
346- Are contracts and invariants explicit enough?
347- Did we reduce or at least not increase complexity?
348- Are classes/modules cohesive?
349- Did we avoid cleverness that harms inspection?
350- Are comments used only where they add value?
351- Is the style consistent with the rest of the codebase?
352
353If any answer is no, revise before shipping.
354
355---
356
357## Final Instruction
358
359When uncertain, choose the option that:
3601. lowers defect risk
3612. improves readability
3623. simplifies control flow
3634. strengthens defensive correctness
3645. keeps the code easier to inspect and maintain
365
366Write code that would stand up to careful review.