CAD FREE CAD Code Refactoring and Quality Questions and Answers 3 — Questions and Answers
Question 1: Which Agile practice involves the entire team reviewing the codebase together to identify quality improvements?
- Mob programming or group code review (Correct answer)
- Sprint retrospective
- Daily standup
- Backlog refinement
Correct answer: Mob programming or group code review
Mob programming and group code reviews bring the whole team together to examine code, share knowledge, and collaboratively identify quality improvements.
Question 2: What does the 'Boy Scout Rule' recommend regarding code quality?
- Always leave the code cleaner than you found it (Correct answer)
- Never modify code that is already working
- Only refactor code during dedicated refactoring sprints
- Write comprehensive documentation before making any changes
Correct answer: Always leave the code cleaner than you found it
The Boy Scout Rule encourages developers to make small improvements to code quality whenever they work in an area, gradually improving the overall codebase.
Question 3: Which refactoring technique is most appropriate when a method has grown too long and contains multiple distinct responsibilities?
- Extract Method (Correct answer)
- Rename Variable
- Move Field
- Encapsulate Collection
Correct answer: Extract Method
Extract Method pulls out cohesive blocks of code into separate, well-named methods, reducing the length and complexity of the original method.
Question 4: What is the main risk of refactoring without adequate test coverage?
- Introducing regressions that go undetected because there are no tests to catch behavioral changes (Correct answer)
- Improving performance too much
- Making the code too readable for junior developers
- Increasing the number of classes beyond the project limit
Correct answer: Introducing regressions that go undetected because there are no tests to catch behavioral changes
Without sufficient tests, refactoring changes may alter the system's behavior in unintended ways that remain undetected until they cause problems in production.
Question 5: In continuous integration, how does automated static code analysis contribute to code quality?
- It detects potential bugs, code smells, and style violations early in the development cycle before code is merged (Correct answer)
- It replaces the need for manual testing entirely
- It automatically fixes all detected issues without developer intervention
- It measures the speed of the deployment pipeline
Correct answer: It detects potential bugs, code smells, and style violations early in the development cycle before code is merged
Static analysis tools scan code for potential issues during the CI pipeline, catching problems before they reach production.
Question 6: What is 'code smell' in the context of Agile software quality?
- A surface indication in the code that usually corresponds to a deeper design problem (Correct answer)
- A syntax error that prevents compilation
- A runtime exception caused by null references
- A deprecated API that has been officially removed
Correct answer: A surface indication in the code that usually corresponds to a deeper design problem
Code smells are patterns in code that suggest the presence of deeper structural or design issues, even though the code may function correctly.
Which Agile practice involves the entire team reviewing the codebase together to identify quality improvements?