Published Oct 17, 2016

Clean Code - How to Write Amazing Functions

    Unlock the essentials of coding mastery with Cold Blocks as they delve into advanced debugging techniques, strategic unit testing for robust code design, and the art of writing clean, efficient functions. Gain valuable insights into refactoring with real-world examples, and enhance your code quality through effective naming and managing function arguments.
    Episode Highlights
    Coding Blocks logo

    Popular Clips

    Episode Highlights

    • Coverage Insights

      Unit test coverage is often misunderstood as a measure of code quality, but it's more about ensuring the design's robustness. Joe Zack emphasizes that unit testing serves as a design tool to shorten feedback cycles and prevent errors, rather than solely ensuring correctness 1. Michael Outlaw points out that high coverage doesn't guarantee thoroughness, as it might only indicate that a method was executed once 1.

      Coverage could just mean that you hit that method one time. That's it.

      --- Alan Underwood

      This highlights the need for a balanced approach, focusing on both proving functionality and identifying potential failures 2.

         

      Robust Testing

      Writing tests that aim to break the code is crucial for ensuring robustness and error handling. Alan Underwood and Michael Outlaw discuss the importance of testing not just for success but also for failure, which can reveal hidden flaws 3. Joe Zack shares his experience with long unit tests, noting that they often involve initializing large objects, which can lead to complex and unwieldy code 4.

      I guess I actually am trying to test that to prove to myself that it doesn't work, and then I need to fix something.

      --- Michael Outlaw

      This approach helps developers anticipate and address potential issues before they become critical 3.

         

      Testing Practices

      Best practices in unit testing involve focusing on edge cases and using tests as a design tool. Alan Underwood suggests considering how code might break and writing tests accordingly, while Michael Outlaw highlights the act and assert format as a structured approach to testing 5. This format involves arranging the state, performing the action, and asserting the result, which can be broken down into private methods for clarity 6.

      Unit test is the one place where I feel like this is acceptable.

      --- Michael Outlaw

      These strategies ensure that tests are comprehensive and maintainable, contributing to overall code quality 5.

    Related Episodes