CS 372 Spring 2016 > Notes for February 17, 2016
CS 372 Spring 2016
Notes
for February 17, 2016
The following is an outline of the February 17 lecture.
Clean Code (cont’d)
Functions [CC chapter 3]
We touched briefly on just one topic from this chapter.
- Command-Query Separation
- A command is a function that performs an action. A query is a function that answers a question. Keep the two kinds of functions distinct.
- This is an expression of the generalized Single Responsibility Principle (SRP): that a software module should have only one well defined responsibility.
- The distinction often (but not always)
corresponds to the distinction between non-const and const
member functions in a C++ class.
- Const member functions generally provide information via a return value.
- Non-const member functions generally have
void
return type.
- Command-query separation can help with:
- Making an API easy to understand.
- Error handling. It is expressed in the C++ rule (which you really do not want to break) that a non-const member function should not return an object by value.
Clean Code will be continued next time.