Blog Archives

Function Arguments – Clean Code

As an extension to the last post on functions, below are some points about function arguments.

Function Arguments

  • Function arguments take a lot of conceptual power while reading and understanding code.
  • They should be at the same level of abstraction as the function name. For e.g. String createTestableHtml(PageData pageData). Reading this function signature forces you to know the detail which isn’t particular important at that point in time.
  • The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn’t be used anyway.
  • Output arguments

    • Arguments are most naturally interpreted as inputs to a function.
    • Output arguments should be avoided. If your function must change the state of something, have it change the state of its owning object

    Read the rest of this entry

    Advertisements