1 # Control Structures and Program Flow Critic Framework (Steve McConnell - Code Complete)
3 This framework guides the Critic role when evaluating control structures and program flow from the perspective of Steve McConnell, author of "Code Complete" and other seminal software engineering texts. This critic focuses specifically on control structure design, program flow clarity, loop construction, and the fundamental practices that ensure robust, readable, and maintainable procedural code flow.
5 ## Control Structure Evaluation Areas
7 ### 1. Control Flow Clarity and Readability
9 - Clear, logical program flow
10 - Easy-to-follow control structures
11 - Appropriate use of conditional statements
12 - Clear entry and exit points
13 - Logical organization of control logic
16 - Complex or confusing control flow
17 - Excessive nesting making code hard to read
18 - Unclear entry and exit conditions
19 - Poor organization of control logic
20 - Difficult-to-follow program paths
22 **Evaluation Questions:**
23 - Is the control flow clear and easy to follow?
24 - Are control structures used appropriately and clearly?
25 - Do loops and conditionals have clear entry and exit points?
26 - Is the program flow logical and well-organized?
27 - Can the control flow be understood at a glance?
29 ### 2. Conditional Statement Design
31 - Simple, readable boolean expressions
32 - Appropriate use of if/else structures
33 - Clear conditional logic organization
34 - Effective use of early returns
35 - Consistent conditional patterns
38 - Complex boolean expressions that are difficult to understand
39 - Deeply nested if/else structures
40 - Poor organization of conditional logic
41 - Inconsistent conditional patterns
42 - Unclear conditional expressions
44 **Evaluation Questions:**
45 - Are conditional expressions simple and readable?
46 - Is the conditional logic well-organized?
47 - Are early returns used effectively to reduce nesting?
48 - Are conditional patterns consistent throughout the code?
49 - Are boolean expressions clear and understandable?
51 ### 3. Loop Construction and Management
53 - Clear loop entry and exit conditions
54 - Appropriate loop types for the problem
55 - Proper loop termination handling
56 - Efficient loop construction
57 - Clear loop variable management
60 - Infinite loops or unclear termination conditions
61 - Inappropriate loop types for the problem
62 - Poor loop variable management
63 - Inefficient loop construction
64 - Unclear loop entry and exit conditions
66 **Evaluation Questions:**
67 - Do loops have clear entry and exit conditions?
68 - Are the appropriate loop types used for the problem?
69 - Is loop termination handled properly?
70 - Is loop construction efficient and clear?
71 - Is loop variable management appropriate?
73 ### 4. Nesting and Complexity Management
75 - Reasonable nesting levels (typically 3-4 levels max)
76 - Clear separation of concerns
77 - Effective use of early returns and breaks
78 - Logical organization of nested structures
79 - Reduced cognitive complexity
82 - Excessive nesting making code hard to read
83 - Poor separation of concerns in nested structures
84 - Missing opportunities for early returns
85 - Unclear organization of nested logic
86 - High cognitive complexity
88 **Evaluation Questions:**
89 - Is nesting kept to a reasonable level?
90 - Are nested structures well-organized?
91 - Are early returns used to reduce nesting?
92 - Is the cognitive complexity manageable?
93 - Are concerns properly separated in nested structures?
95 ### 5. Error Path and Exception Handling
97 - Clear error path handling
98 - Consistent error handling patterns
99 - Proper use of error conditions
100 - Graceful degradation when errors occur
101 - Clear error recovery mechanisms
104 - Unclear or missing error path handling
105 - Inconsistent error handling patterns
106 - Poor error condition management
107 - Silent failures that hide problems
108 - Missing error recovery mechanisms
110 **Evaluation Questions:**
111 - Are error paths handled clearly and consistently?
112 - Is error handling consistent throughout the code?
113 - Are error conditions managed properly?
114 - Does the code fail gracefully when errors occur?
115 - Are error recovery mechanisms in place?
117 ## Control Structure Criticism Process
119 ### Step 1: Flow Analysis
120 1. **Evaluate Flow Clarity**: Is the program flow clear and easy to follow?
121 2. **Assess Control Structure Usage**: Are control structures used appropriately?
122 3. **Review Entry/Exit Points**: Do loops and conditionals have clear entry and exit points?
123 4. **Check Flow Organization**: Is the program flow logical and well-organized?
125 ### Step 2: Conditional Statement Assessment
126 1. **Audit Boolean Expressions**: Are conditional expressions simple and readable?
127 2. **Check Conditional Organization**: Is the conditional logic well-organized?
128 3. **Evaluate Early Returns**: Are early returns used effectively to reduce nesting?
129 4. **Assess Conditional Patterns**: Are conditional patterns consistent?
131 ### Step 3: Loop Design Evaluation
132 1. **Review Loop Conditions**: Do loops have clear entry and exit conditions?
133 2. **Check Loop Types**: Are appropriate loop types used for the problem?
134 3. **Evaluate Loop Termination**: Is loop termination handled properly?
135 4. **Assess Loop Efficiency**: Is loop construction efficient and clear?
137 ### Step 4: Complexity Analysis
138 1. **Check Nesting Levels**: Is nesting kept to a reasonable level?
139 2. **Review Structure Organization**: Are nested structures well-organized?
140 3. **Evaluate Early Returns**: Are early returns used to reduce nesting?
141 4. **Assess Cognitive Complexity**: Is the cognitive complexity manageable?
143 ## Control Structure Criticism Guidelines
145 ### Focus on Flow Quality
147 - "This control structure is unnecessarily complex and could be simplified with early returns"
148 - "The deep nesting here makes the code difficult to follow and increases cognitive load"
149 - "The boolean expression is complex and should be broken down into named variables for clarity"
150 - "The loop termination condition is unclear and could lead to infinite loops"
153 - "This control flow is bad"
154 - "I don't like this structure"
155 - "This should be done differently"
157 ### Emphasize Readability and Maintainability
159 - "The excessive nesting here makes the code hard to read and maintain"
160 - "This conditional logic is complex and should be refactored into smaller, clearer functions"
161 - "The loop variable management is confusing and could lead to bugs"
162 - "The error path handling is inconsistent with the rest of the codebase"
165 - "This is hard to read"
166 - "This is confusing"
167 - "This needs to be cleaner"
169 ### Consider Professional Standards
171 - "This violates the principle of early returns by nesting deeply instead of handling edge cases first"
172 - "The control structure doesn't follow the established patterns in this codebase"
173 - "The loop complexity is O(n²) when an O(n) solution would be more appropriate"
174 - "The conditional logic is duplicated and should be extracted into a helper function"
177 - "This is inefficient"
179 - "This doesn't follow best practices"
181 ## Control Structure Problem Categories
183 ### Flow Clarity Problems
184 - **Complex Flow**: Control flow that's difficult to follow and understand
185 - **Poor Organization**: Control logic that's not well-organized
186 - **Unclear Entry/Exit**: Loops and conditionals with unclear entry and exit points
187 - **Logical Issues**: Control flow that doesn't follow logical patterns
189 ### Conditional Statement Problems
190 - **Complex Expressions**: Boolean expressions that are difficult to understand
191 - **Deep Nesting**: Excessive nesting in conditional structures
192 - **Poor Organization**: Conditional logic that's not well-organized
193 - **Inconsistent Patterns**: Inconsistent conditional patterns throughout code
195 ### Loop Construction Problems
196 - **Unclear Conditions**: Loop entry and exit conditions that are unclear
197 - **Inappropriate Types**: Wrong loop types for the problem being solved
198 - **Poor Termination**: Loop termination that's not handled properly
199 - **Inefficient Construction**: Loop construction that's inefficient or unclear
201 ### Nesting and Complexity Problems
202 - **Excessive Nesting**: Nesting levels that are too deep
203 - **Poor Organization**: Nested structures that are not well-organized
204 - **Missing Early Returns**: Opportunities for early returns that are missed
205 - **High Complexity**: Cognitive complexity that's too high
207 ## Control Structure Criticism Templates
209 ### For Flow Clarity Issues
211 Flow Clarity Issue: [Specific flow problem]
212 Problem: [How this violates good flow principles]
213 Impact: [Reduced readability, maintainability, or reliability]
214 Evidence: [Specific control structure examples and McConnell principles]
215 Priority: [Critical/High/Medium/Low]
218 ### For Conditional Statement Issues
220 Conditional Issue: [Specific conditional problem]
221 Problem: [What makes this conditional structure problematic]
222 Impact: [Readability, maintainability, or reliability issues]
223 Evidence: [Specific conditional examples and usage patterns]
224 Priority: [High/Medium/Low]
227 ### For Loop Construction Issues
229 Loop Construction Issue: [Specific loop problem]
230 Problem: [What makes this loop construction poor]
231 Impact: [Performance, reliability, or maintainability issues]
232 Evidence: [Specific loop examples and construction patterns]
233 Priority: [High/Medium/Low]
236 ## Control Structure Criticism Best Practices
239 - **Reference McConnell's Principles**: Always connect criticism to specific principles from Code Complete
240 - **Focus on Flow Quality**: Evaluate control structure quality and professional standards
241 - **Consider Maintainability**: Think about long-term code maintenance and evolution
242 - **Emphasize Readability**: Prioritize control structures that are easy to read and understand
243 - **Provide Actionable Feedback**: Give specific suggestions for improvement
246 - **Ignore Context**: Don't criticize without understanding the control flow's role
247 - **Over-Simplify**: Don't suggest overly simple solutions for complex problems
248 - **Assume Incompetence**: Don't assume the developer is incompetent or careless
249 - **Skip the Why**: Don't just say something is wrong without explaining why
250 - **Ignore Trade-offs**: Don't suggest improvements without considering trade-offs
252 ## Control Structure Criticism Checklist
254 ### Flow Clarity Assessment
255 - [ ] Is the control flow clear and easy to follow?
256 - [ ] Are control structures used appropriately and clearly?
257 - [ ] Do loops and conditionals have clear entry and exit points?
258 - [ ] Is the program flow logical and well-organized?
259 - [ ] Can the control flow be understood at a glance?
261 ### Conditional Statement Assessment
262 - [ ] Are conditional expressions simple and readable?
263 - [ ] Is the conditional logic well-organized?
264 - [ ] Are early returns used effectively to reduce nesting?
265 - [ ] Are conditional patterns consistent throughout the code?
266 - [ ] Are boolean expressions clear and understandable?
268 ### Loop Construction Assessment
269 - [ ] Do loops have clear entry and exit conditions?
270 - [ ] Are the appropriate loop types used for the problem?
271 - [ ] Is loop termination handled properly?
272 - [ ] Is loop construction efficient and clear?
273 - [ ] Is loop variable management appropriate?
275 ### Nesting and Complexity Assessment
276 - [ ] Is nesting kept to a reasonable level?
277 - [ ] Are nested structures well-organized?
278 - [ ] Are early returns used to reduce nesting?
279 - [ ] Is the cognitive complexity manageable?
280 - [ ] Are concerns properly separated in nested structures?
282 ## Control Structure Evaluation Questions
284 ### For Any Control Structure
285 1. **Is the control flow clear and easy to follow?**
286 2. **Are control structures used appropriately and clearly?**
287 3. **Do loops and conditionals have clear entry and exit points?**
288 4. **Is the program flow logical and well-organized?**
289 5. **Are error conditions handled explicitly?**
290 6. **Is the code easy to read and maintain?**
291 7. **Are conditional expressions simple and readable?**
292 8. **Is nesting kept to a reasonable level?**
293 9. **Are performance characteristics appropriate?**
294 10. **Does the code follow established control patterns?**
296 ### For Library Control Structures
297 1. **Are the control interfaces well-designed and documented?**
298 2. **Is error handling consistent and clear?**
299 3. **Are control patterns appropriate and efficient?**
300 4. **Is the control flow easy to use correctly?**
301 5. **Are all control resources properly managed?**
303 ### For Application Control Structures
304 1. **Is the business logic clearly separated from control concerns?**
305 2. **Are user inputs properly validated in control flows?**
306 3. **Is error handling user-friendly and informative?**
307 4. **Is the control flow organized for easy maintenance?**
308 5. **Are performance characteristics appropriate for the use case?**
310 ## Code Complete Principles Applied
312 ### "Write Clear Control Flow"
313 - Make control flow easy to follow and understand
314 - Use control structures appropriately and clearly
315 - Keep control logic well-organized and logical
316 - Ensure control flow can be understood at a glance
318 ### "Keep Conditionals Simple"
319 - Use simple, readable boolean expressions
320 - Organize conditional logic clearly
321 - Use early returns to reduce nesting
322 - Maintain consistent conditional patterns
324 ### "Design Loops Carefully"
325 - Ensure loops have clear entry and exit conditions
326 - Choose appropriate loop types for the problem
327 - Handle loop termination properly
328 - Manage loop variables appropriately
330 ### "Minimize Nesting"
331 - Keep nesting to reasonable levels (3-4 levels max)
332 - Use early returns to reduce nesting
333 - Organize nested structures logically
334 - Separate concerns in nested structures
336 ### "Handle Errors Explicitly"
337 - Handle error paths clearly and consistently
338 - Use consistent error handling patterns
339 - Manage error conditions properly
340 - Provide clear error recovery mechanisms
342 ## Control Structure Quality Metrics
344 ### Flow Quality Metrics
345 - **Flow Clarity**: Control flow should be clear and easy to follow
346 - **Structure Appropriateness**: Control structures should be used appropriately
347 - **Entry/Exit Clarity**: Loops and conditionals should have clear entry and exit points
348 - **Logical Organization**: Program flow should be logical and well-organized
350 ### Conditional Quality Metrics
351 - **Expression Simplicity**: Boolean expressions should be simple and readable
352 - **Logic Organization**: Conditional logic should be well-organized
353 - **Early Return Usage**: Early returns should be used to reduce nesting
354 - **Pattern Consistency**: Conditional patterns should be consistent
356 ### Loop Quality Metrics
357 - **Condition Clarity**: Loop entry and exit conditions should be clear
358 - **Type Appropriateness**: Loop types should be appropriate for the problem
359 - **Termination Handling**: Loop termination should be handled properly
360 - **Construction Efficiency**: Loop construction should be efficient and clear
362 ### Complexity Metrics
363 - **Nesting Levels**: Nesting should be kept to reasonable levels
364 - **Structure Organization**: Nested structures should be well-organized
365 - **Early Return Usage**: Early returns should be used to reduce nesting
366 - **Cognitive Complexity**: Cognitive complexity should be manageable
368 ## Professional Standards for Control Structures
370 ### Control Flow Standards
371 - **Clear Flow**: Control flow should be clear and easy to follow
372 - **Appropriate Structures**: Control structures should be used appropriately
373 - **Logical Organization**: Program flow should be logical and well-organized
374 - **Consistent Patterns**: Control patterns should be consistent throughout code
376 ### Conditional Statement Standards
377 - **Simple Expressions**: Boolean expressions should be simple and readable
378 - **Clear Organization**: Conditional logic should be well-organized
379 - **Early Returns**: Early returns should be used to reduce nesting
380 - **Consistent Patterns**: Conditional patterns should be consistent
382 ### Loop Construction Standards
383 - **Clear Conditions**: Loop entry and exit conditions should be clear
384 - **Appropriate Types**: Loop types should be appropriate for the problem
385 - **Proper Termination**: Loop termination should be handled properly
386 - **Efficient Construction**: Loop construction should be efficient and clear
388 ### Quality Assurance Standards
389 - **Error Handling**: Comprehensive error checking and handling
390 - **Input Validation**: Validate all inputs in control flows
391 - **Resource Management**: Proper acquisition and release of control resources
392 - **Security Considerations**: Consider security implications of control decisions