Clean Code (Martin) Reading Discussion Questions

Click to expand the chapter of interest.

Ch 5: Formatting

  1. Explain how the style of your code can last longer than the code itself.
  2. What is vertical distance? Why is it important?
  3. How does vertical distance relate to protected variables and inheritance?
  4. Describe three important points related to the horizontal formatting of code (such as length/density/alignment/indentation).


Ch 6: Objects and Data Structures

  1. What is the difference between the following?
    • Having setters/getters for each member field of an object
    • Good use of hiding implementation
  2. What is the difference between an object and a data structure?
  3. What is the Law of Demeter? Why is it important? How does it help with "train wrecks"?
  4. What is a data transfer object? What is an "active record"?
  5. 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

  1. What's wrong with using return codes?
  2. Explain the benefit of writing the exception handling code before writing the logic.
  3. What is the Open/Closed Principle?
  4. What is an unchecked exception? Explain why should they be preferred over checked exceptions?
  5. Why should code throw exceptions based on how client code will use them, rather than based on the causes of the errors?
  6. 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.
  7. What is wrong with Null? How can you change your code to not return Null?


Ch 8: Boundaries

  1. What is the advantage to wrapping 3rd-part code?
  2. What is the point of the "Learning log4j" section?
  3. What are the benefits of writing tests for 3rd party code?
  4. 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

  1. What are the 3 laws of TDD? What is the advantage of following these laws?
  2. Why should tests be kept clean? What is the cost of having unclean tests?
  3. Explain why are readable tests so important?
  4. What is your opinion of the testing shown in Listing 9-5 compared to the other ways of writing the tests?
  5. What is the given-when-then convention?
  6. Which of the FIRST rules is violated by each of the following issues with testing?
    1. The tests often fail for one developer, but work for another
    2. The tests can fail if you run them in the incorrect order
    3. Test results are accessible by searching for "ERROR:" in the test log file.
    4. Testing department completes creating unit tests for code within an average of 2 weeks of when code is merged to master.
    5. 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

  1. What is the SRP? Explain how it fits into an individual developer's process of writing working clean code?
  2. What heuristic does the book give to measure the cohesion of a method?
  3. Explain why breaking up a large function can reduce the cohesion of a class.
  4. What is the OCP? How does it relate to organizing change?
  5. Discuss how this chapter suggests one can reduce coupling?


Ch 11: Systems

  1. Explain what is the separation of concerns design technique.
  2. What is the problem of a module instantiating other components itself?
  3. What is a Factory?
  4. In your own words, what is dependency injection? Explain the benefit of using it.
  5. What are "cross-cutting concerns". What is the recommended technique to handle these?
  6. Discuss how coupling code to a framework affects its testability.


Ch 12: Emergence

  1. Why is "Run All The Tests" the most important of the rules?
  2. What is "reuse in the small?" Explain how it can be applied, and its benefit.
  3. Look up the principle of least surprise. Explain how it relates to "Expressive".
  4. Describe how applying principles such as maximizing cohesion, or maximizing decoupling, could lead to having too many classes?


Ch 13: Concurrency

  1. Write out most of the important recommendations in this chapter. You decide which ones you may skip (but there shouldn't be many skipped).
  2. 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.