As an extension to the last post on functions, below are some points about 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.
- 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
While watching the episode 3 of the clean coders video I noted down some important points.
Functions are the first line of code organization in your application.
- The first rule to having clean functions is that they should be small.
- Typically classes hide in large functions.
- If you find functions that can be divided into several functional areas and you have variables that are used by all those areas then what you really have is a class. After all, a class is a group of functions that use a common set of variables.