This blog post is part of a series of blog posts concerning a Clean Code study circle that we developers at Admeta are persuing during 2009. Here you can find an introduction concerning the question why we are doing this and here you can find an overview of all chapters as well as some study circle recommendations.
Questions: Chapter 3 Functions
Reading quiz:
- Why should functions be small?
- Why do function arguments take a lot of conceptual powers?
- How do you avoid too many parameters in a function?
- What is temporal coupling?
- When would you make a difference between returning a value from a function and setting the value as a class field within the method?
Design considerations:
- Is it ok to have many different levels of abstractions within the same method / class?
- How do you see C# v3 Extension Methods fit into what Robert Martin writes in this chapter?
- If you don't use flag arguments, and instead use several unique methods, how do you avoid duplication in the code?
- Do you see any design choice in which error codes code be used and still avoid creating a dependency magnet, as well as avoiding OCP violation?
Questions to ponder upon:
- Functions are also sometimes referred to as methods (no return value). Why does not Robert Martin mention methods in the chapter?
- If functions should only contain 6-8 lines, would you prefer not to waste space using {} when you have an if statement followed by a one line block statement?
- Say that a function is doing several things, but these things can be considered as one thing on a higher abstraction level. How do you label that function if you can't find a good name to describe that higher abstraction layer?
The context of our study sessions is restricted to .NET and C#, thus the nature of the questions above.