Clean Code (Martin) Reading Discussion Questions
Click to expand the chapter of interest.
Ch 5: Formatting
- Explain how the style of your code can last longer than the code itself.
- What is vertical distance? Why is it important?
- How does vertical distance relate to protected variables and inheritance?
- Describe three important points related to the horizontal formatting of code (such as length/density/alignment/indentation).
Ch 6: Objects and Data Structures
- What is the difference between the following?
- Having setters/getters for each member field of an object
- Good use of hiding implementation
- What is the difference between an object and a data structure?
- What is the Law of Demeter? Why is it important? How does it help with "train wrecks"?
- What is a data transfer object? What is an "active record"?
- When designing a program to work with data, when would it be best to use a data structure? When would it be best to use an object?
Ch 7: Error Handling
- What's wrong with using return codes?
- Explain the benefit of writing the exception handling code before writing the logic.
- What is the Open/Closed Principle?
- What is an unchecked exception? Explain why should they be preferred over checked exceptions?
- Why should code throw exceptions based on how client code will use them, rather than based on the causes of the errors?
- How can existing code (such as an external library) which throws many different types of exceptions be integrated into a system without having all the client code need to handle the many different types of exceptions? Explain.
- What is wrong with Null? How can you change your code to not return Null?
Ch 8: Boundaries
- What is the advantage to wrapping 3rd-part code?
- What is the point of the "Learning
log4j
" section? - What are the benefits of writing tests for 3rd party code?
- Explain the motivation behind the statement, "We should avoid letting too much of our code know about the third-party particulars" (Martin, Clean Code, p120).
Ch 9: Unit Tests
- What are the 3 laws of TDD? What is the advantage of following these laws?
- Why should tests be kept clean? What is the cost of having unclean tests?
- Explain why are readable tests so important?
- What is your opinion of the testing shown in Listing 9-5 compared to the other ways of writing the tests?
- What is the given-when-then convention?
- Which of the FIRST rules is violated by each of the following issues with testing?
- The tests often fail for one developer, but work for another
- The tests can fail if you run them in the incorrect order
- Test results are accessible by searching for "ERROR:" in the test log file.
- Testing department completes creating unit tests for code within an average of 2 weeks of when code is merged to master.
- Tests require dedicated resources on a server, so while one developer is running the tests no other developers may start a test.
Ch 10: Classes
- What is the SRP? Explain how it fits into an individual developer's process of writing working clean code?
- What heuristic does the book give to measure the cohesion of a method?
- Explain why breaking up a large function can reduce the cohesion of a class.
- What is the OCP? How does it relate to organizing change?
- Discuss how this chapter suggests one can reduce coupling?
Ch 11: Systems
- Explain what is the separation of concerns design technique.
- What is the problem of a module instantiating other components itself?
- What is a Factory?
- In your own words, what is dependency injection? Explain the benefit of using it.
- What are "cross-cutting concerns". What is the recommended technique to handle these?
- Discuss how coupling code to a framework affects its testability.
Ch 12: Emergence
- Why is "Run All The Tests" the most important of the rules?
- What is "reuse in the small?" Explain how it can be applied, and its benefit.
- Look up the principle of least surprise. Explain how it relates to "Expressive".
- Describe how applying principles such as maximizing cohesion, or maximizing decoupling, could lead to having too many classes?
Ch 13: Concurrency
- Write out most of the important recommendations in this chapter. You decide which ones you may skip (but there shouldn't be many skipped).
- Pick two of the recommendations which you feel you have learned most from. Explain what it was you learned and how you intend to apply the recommendations this semester, or in the future.