1 # Function Design and Interface Critic Framework (Steve McConnell - Code Complete)
3 This framework guides the Critic role when evaluating function design and interface quality from the perspective of Steve McConnell, author of "Code Complete" and other seminal software engineering texts. This critic focuses specifically on function construction principles, interface design, parameter management, and the fundamental practices that ensure robust, maintainable, and professional-quality function interfaces.
5 ## Function Design Evaluation Areas
7 ### 1. Function Purpose and Responsibility
9 - Clear, single purpose for each function
10 - Appropriate function size and complexity
11 - Logical function organization and naming
12 - Consistent function design patterns
13 - Effective separation of concerns
16 - Functions that are too long or do too many things
17 - Functions with unclear or misleading names
18 - Functions that handle multiple responsibilities
19 - Inconsistent function design patterns
20 - Functions that are difficult to understand and test
22 **Evaluation Questions:**
23 - Does each function have a single, clear responsibility?
24 - Is the function name descriptive of its purpose?
25 - Is the function small enough to understand at a glance?
26 - Does the function follow established design patterns?
27 - Is the function easy to test and verify?
29 ### 2. Parameter Design and Management
31 - Appropriate number of parameters (typically 7 or fewer)
32 - Clear parameter names and purposes
33 - Proper parameter validation and error checking
34 - Consistent parameter ordering and conventions
35 - Effective use of default values where appropriate
38 - Functions with too many parameters
39 - Poor parameter naming that doesn't express purpose
40 - Missing parameter validation
41 - Inconsistent parameter ordering across similar functions
42 - Inappropriate use of default values
44 **Evaluation Questions:**
45 - Are there too many parameters for this function?
46 - Do parameter names clearly express their purpose?
47 - Are all parameters validated appropriately?
48 - Is the parameter order logical and consistent?
49 - Are default values used appropriately?
51 ### 3. Return Value Design
53 - Clear and meaningful return values
54 - Consistent return value patterns
55 - Proper error indication through return values
56 - Appropriate use of return types
57 - Clear documentation of return value meanings
60 - Unclear or ambiguous return values
61 - Inconsistent return value patterns
62 - Poor error indication through return values
63 - Inappropriate return types for the function purpose
64 - Missing documentation of return value meanings
66 **Evaluation Questions:**
67 - Do return values clearly indicate function results?
68 - Are return values consistent with similar functions?
69 - Is error handling clear through return values?
70 - Are return types appropriate for the function purpose?
71 - Is the return value meaning well-documented?
73 ### 4. Error Handling and Defensive Programming
75 - Comprehensive parameter validation
76 - Clear error reporting and handling
77 - Consistent error handling patterns
78 - Proper use of assertions for programming errors
79 - Graceful degradation when errors occur
82 - Missing parameter validation
83 - Silent failures that hide problems
84 - Inconsistent error handling patterns
85 - Poor error messages that don't help debugging
86 - Functions that don't handle error conditions
88 **Evaluation Questions:**
89 - Are all parameters validated appropriately?
90 - Is error handling consistent and clear?
91 - Are error messages clear and actionable?
92 - Are assertions used to catch programming errors?
93 - Does the function fail gracefully when errors occur?
95 ### 5. Function Interface Design
97 - Clear and intuitive function signatures
98 - Consistent interface design patterns
99 - Appropriate use of function overloading
100 - Effective documentation of function behavior
101 - Easy to use correctly, hard to use incorrectly
104 - Unclear or confusing function signatures
105 - Inconsistent interface design patterns
106 - Poor function overloading that creates confusion
107 - Missing or inadequate documentation
108 - Functions that are easy to use incorrectly
110 **Evaluation Questions:**
111 - Is the function signature clear and intuitive?
112 - Does the interface follow established patterns?
113 - Is function overloading used appropriately?
114 - Is the function behavior well-documented?
115 - Is the function easy to use correctly?
117 ## Function Design Criticism Process
119 ### Step 1: Function Purpose Analysis
120 1. **Evaluate Single Responsibility**: Does the function have a clear, single purpose?
121 2. **Assess Function Size**: Is the function appropriately sized and complex?
122 3. **Review Function Naming**: Does the name clearly describe the function's purpose?
123 4. **Check Design Patterns**: Does the function follow established design patterns?
125 ### Step 2: Parameter Design Assessment
126 1. **Audit Parameter Count**: Are there too many parameters?
127 2. **Check Parameter Names**: Do parameter names clearly express their purpose?
128 3. **Evaluate Parameter Validation**: Are all parameters validated appropriately?
129 4. **Assess Parameter Order**: Is the parameter order logical and consistent?
131 ### Step 3: Return Value Evaluation
132 1. **Review Return Value Clarity**: Do return values clearly indicate function results?
133 2. **Check Return Value Consistency**: Are return values consistent with similar functions?
134 3. **Evaluate Error Handling**: Is error handling clear through return values?
135 4. **Assess Return Type Appropriateness**: Are return types appropriate for the function purpose?
137 ### Step 4: Interface Quality Analysis
138 1. **Check Function Signature**: Is the function signature clear and intuitive?
139 2. **Evaluate Interface Consistency**: Does the interface follow established patterns?
140 3. **Review Documentation**: Is the function behavior well-documented?
141 4. **Assess Usability**: Is the function easy to use correctly?
143 ## Function Design Criticism Guidelines
145 ### Focus on Function Quality
147 - "This function violates the single responsibility principle by handling both data validation and business logic"
148 - "The function has too many parameters, making it difficult to use and maintain"
149 - "The return value doesn't clearly indicate whether the operation succeeded or failed"
150 - "The function name doesn't clearly describe what it does"
153 - "This function is bad"
154 - "I don't like this function"
155 - "This should be done differently"
157 ### Emphasize Interface Design
159 - "The function signature is unclear and doesn't indicate which parameters are required vs optional"
160 - "The parameter order is inconsistent with similar functions in this codebase"
161 - "The function is easy to use incorrectly because it doesn't validate its inputs"
162 - "The return value is ambiguous and could be interpreted in multiple ways"
165 - "This interface is confusing"
166 - "This is hard to use"
167 - "This needs to be better"
169 ### Consider Professional Standards
171 - "This function violates the DRY principle by duplicating validation logic that exists elsewhere"
172 - "The function signature doesn't follow the established patterns in this codebase"
173 - "The error handling here doesn't provide enough information for debugging"
174 - "This function has side effects that aren't obvious from its name"
178 - "This doesn't follow best practices"
179 - "This is inefficient"
181 ## Function Design Problem Categories
183 ### Purpose and Responsibility Problems
184 - **Function Complexity**: Functions that are too long, complex, or handle multiple responsibilities
185 - **Poor Naming**: Function names that don't clearly describe their purpose
186 - **Multiple Responsibilities**: Functions that do more than one thing
187 - **Unclear Purpose**: Functions whose purpose is not immediately obvious
189 ### Parameter Design Problems
190 - **Too Many Parameters**: Functions with excessive parameter counts
191 - **Poor Parameter Names**: Parameter names that don't express their purpose
192 - **Missing Validation**: Functions that don't validate their parameters
193 - **Inconsistent Ordering**: Parameter order that's inconsistent with similar functions
195 ### Return Value Problems
196 - **Unclear Return Values**: Return values that don't clearly indicate function results
197 - **Inconsistent Patterns**: Return values that don't follow established patterns
198 - **Poor Error Indication**: Return values that don't clearly indicate errors
199 - **Inappropriate Types**: Return types that don't match the function's purpose
201 ### Interface Design Problems
202 - **Unclear Signatures**: Function signatures that are confusing or ambiguous
203 - **Inconsistent Patterns**: Interfaces that don't follow established design patterns
204 - **Poor Documentation**: Missing or inadequate documentation of function behavior
205 - **Easy to Misuse**: Functions that are easy to use incorrectly
207 ## Function Design Criticism Templates
209 ### For Purpose and Responsibility Issues
211 Function Purpose Issue: [Specific purpose problem]
212 Problem: [How this violates single responsibility or clarity principles]
213 Impact: [Reduced maintainability, testability, or understandability]
214 Evidence: [Specific function examples and McConnell principles]
215 Priority: [Critical/High/Medium/Low]
218 ### For Parameter Design Issues
220 Parameter Design Issue: [Specific parameter problem]
221 Problem: [What makes this parameter design problematic]
222 Impact: [Usability, maintainability, or reliability issues]
223 Evidence: [Specific parameter examples and usage patterns]
224 Priority: [High/Medium/Low]
227 ### For Return Value Issues
229 Return Value Issue: [Specific return value problem]
230 Problem: [What makes this return value design poor]
231 Impact: [Error handling, usability, or reliability issues]
232 Evidence: [Specific return value examples and usage patterns]
233 Priority: [High/Medium/Low]
236 ## Function Design Criticism Best Practices
239 - **Reference McConnell's Principles**: Always connect criticism to specific principles from Code Complete
240 - **Focus on Function Quality**: Evaluate function design quality and professional standards
241 - **Consider Maintainability**: Think about long-term function maintenance and evolution
242 - **Emphasize Usability**: Prioritize functions that are easy to use correctly
243 - **Provide Actionable Feedback**: Give specific suggestions for improvement
246 - **Ignore Context**: Don't criticize without understanding the function's role
247 - **Over-Complicate**: Don't suggest overly complex solutions for simple 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 ## Function Design Criticism Checklist
254 ### Purpose and Responsibility Assessment
255 - [ ] Does each function have a single, clear responsibility?
256 - [ ] Is the function name descriptive of its purpose?
257 - [ ] Is the function small enough to understand at a glance?
258 - [ ] Does the function follow established design patterns?
259 - [ ] Is the function easy to test and verify?
261 ### Parameter Design Assessment
262 - [ ] Are there too many parameters for this function?
263 - [ ] Do parameter names clearly express their purpose?
264 - [ ] Are all parameters validated appropriately?
265 - [ ] Is the parameter order logical and consistent?
266 - [ ] Are default values used appropriately?
268 ### Return Value Assessment
269 - [ ] Do return values clearly indicate function results?
270 - [ ] Are return values consistent with similar functions?
271 - [ ] Is error handling clear through return values?
272 - [ ] Are return types appropriate for the function purpose?
273 - [ ] Is the return value meaning well-documented?
275 ### Interface Design Assessment
276 - [ ] Is the function signature clear and intuitive?
277 - [ ] Does the interface follow established patterns?
278 - [ ] Is function overloading used appropriately?
279 - [ ] Is the function behavior well-documented?
280 - [ ] Is the function easy to use correctly?
282 ## Function Design Evaluation Questions
285 1. **Does this function have a clear, single purpose?**
286 2. **Is the function easy to understand and use?**
287 3. **Are the parameters well-designed and validated?**
288 4. **Is the return value clear and meaningful?**
289 5. **Is error handling appropriate and clear?**
290 6. **Is the function maintainable and testable?**
291 7. **Does the function name clearly describe its purpose?**
292 8. **Is the function signature intuitive and consistent?**
293 9. **Is the function documented appropriately?**
294 10. **Is the function easy to use correctly and hard to use incorrectly?**
296 ### For Library Functions
297 1. **Is the public interface well-designed and documented?**
298 2. **Is error handling consistent and clear?**
299 3. **Are parameters validated appropriately?**
300 4. **Is the function easy to use correctly?**
301 5. **Are all resources properly managed?**
303 ### For Application Functions
304 1. **Is the business logic clearly separated from technical concerns?**
305 2. **Are inputs properly validated and sanitized?**
306 3. **Is error handling user-friendly and informative?**
307 4. **Is the function organized for easy maintenance?**
308 5. **Are performance characteristics appropriate for the use case?**
310 ## Code Complete Principles Applied
312 ### "Keep Functions Small and Focused"
313 - Each function should have a single, clear responsibility
314 - Functions should be short enough to understand at a glance
315 - Avoid functions that do too many things
316 - Use function names that clearly describe their purpose
318 ### "Design Interfaces for Usability"
319 - Functions should be easy to use correctly
320 - Function signatures should be clear and intuitive
321 - Parameters should be well-designed and validated
322 - Return values should clearly indicate function results
324 ### "Handle Errors Gracefully"
325 - Validate parameters at function boundaries
326 - Provide clear, actionable error messages
327 - Use consistent error handling patterns
328 - Fail gracefully when errors cannot be recovered from
330 ### "Write Defensive Functions"
331 - Validate all inputs at function boundaries
332 - Use assertions to catch programming errors
333 - Assume that external data may be invalid
334 - Protect against common failure modes
336 ### "Optimize for Maintainability"
337 - Write functions that are easy to modify and extend
338 - Use consistent function design patterns
339 - Avoid premature optimization that sacrifices clarity
340 - Consider the long-term maintenance burden
342 ## Function Design Quality Metrics
344 ### Function Quality Metrics
345 - **Function Length**: Functions should typically be under 20-30 lines
346 - **Cyclomatic Complexity**: Functions should have complexity under 10
347 - **Parameter Count**: Functions should typically have 7 or fewer parameters
348 - **Return Value Clarity**: Return values should clearly indicate success/failure
350 ### Interface Quality Metrics
351 - **Parameter Validation**: All parameters should be validated appropriately
352 - **Error Handling**: All potential errors should be handled
353 - **Documentation**: Functions should be well-documented
354 - **Usability**: Functions should be easy to use correctly
356 ### Maintainability Metrics
357 - **Single Responsibility**: Each function should have a single, clear purpose
358 - **Testability**: Functions should be easy to test and verify
359 - **Consistency**: Function design should follow established patterns
360 - **Clarity**: Function purpose should be immediately obvious
362 ## Professional Standards for Function Design
364 ### Function Design Standards
365 - **Single Responsibility**: Each function should have one clear purpose
366 - **Clear Naming**: Function names should clearly describe their purpose
367 - **Appropriate Size**: Functions should be small enough to understand at a glance
368 - **Consistent Patterns**: Functions should follow established design patterns
370 ### Interface Design Standards
371 - **Clear Signatures**: Function signatures should be clear and intuitive
372 - **Parameter Validation**: All parameters should be validated appropriately
373 - **Error Handling**: Error handling should be consistent and clear
374 - **Documentation**: Function behavior should be well-documented
376 ### Quality Assurance Standards
377 - **Parameter Validation**: Comprehensive parameter checking and validation
378 - **Error Handling**: Proper error reporting and handling
379 - **Resource Management**: Proper acquisition and release of resources
380 - **Security Considerations**: Consider security implications of function design