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

    • Function Size

      The team discusses the ideal size of functions, emphasizing that smaller functions are easier to understand and maintain. Michael Outlaw highlights that if a function takes more than three minutes to comprehend, it's too complex 1. Alan Underwood adds that functions should be concise, ideally no more than 20 lines long 1. Joe Zack shares his experience of refining a complex function over two hours to improve readability and efficiency 2.

      All functions start as trees until you whittle them down to toothpicks.

      --- Michael Outlaw

         

      Naming Conventions

      Naming conventions play a crucial role in code readability and maintainability. Michael Outlaw advises against using vague names like 'manager' or 'helper,' advocating for more descriptive names 3. Joe Zack emphasizes that function names should clearly indicate their purpose, and long names are acceptable if they enhance clarity 4. He also notes the importance of using standard naming conventions like 'get' and 'set' appropriately 4.

      Functions should be verb names and your properties should be noun names.

      --- Michael Outlaw

         

      Function Arguments

      Managing function arguments effectively is essential for clean code. Joe Zack points out that functions should ideally have no more than two arguments to simplify testing and reduce complexity 5. Michael Outlaw agrees, noting that too many arguments can lead to clutter and make the code harder to maintain 6. They also discuss the use of configuration objects to handle multiple arguments more efficiently 6.

      The more arguments you add, the more difficult it is to isolate things to that one particular method.

      --- Alan Underwood

    Related Episodes