CS 372 Spring 2016 > Notes for February 15, 2016
CS 372 Spring 2016
Notes
for February 15, 2016
The following is an outline of the February 15 lecture.
Clean Code
Background
- Book:
Clean Code: A Handbook of Agile Software Craftsmanship,
by Robert C. Martin,
2009.
- Recommended!
- This inspired
the Clean Code Developer Initiative/School,
started by
Stefan Lieser & Ralph Westfall
in 2009.
- Alas, incomplete web pages, much of material in German.
- However, some good ideas. Worth a look.
- Full of principles: you are allowed to disagree.
- These include far more material than we can cover. We will hit some of the highlights.
What is Clean Code [CC intro & chapter 1]
- The only valid measure of code quality: WTFs per minute.
- Total Cost of Owning a Mess
- Defining Clean Code:
noteworthy phrases from interviews with famous programmers
- Elegant.
- Efficient.
- Simple.
- Direct.
- Can be read & enhanced by a developer other than its initial author.
- Looks like it was written by someone who cares.
- I like this one. -GGC-
- There is nothing obvious we can do to make it better.
- Makes it look like the [programming] language was made for the problem.
- The Boy Scout Rule
- Leave the campsite cleaner than when you found it.
- So: write clean code, but also edit code to make it cleaner.
Meaningful Names [CC chapter 2]
- Use names that reveal intention.
- Avoid disinformation.
- Make meaningful distinctions.
- Names should be: pronounceable, searchable.
- Avoid “encodings”
- Example of an encoding:
beginning names of data members with “
m_
”. - I don’t really agree with this one. -GGC-
- Example of an encoding:
beginning names of data members with “
- Misc
- Name of a class: a noun.
- Name of a member function: a verb.
- Programmer terminology is okay:
AccountQueue
. - If no programmer-ese is available, get terminology from the problem domain.
- Context is good.
- What is “
state
”? Are we running a state machine? Keeping track of solid vs. liquid vs. gas? Storing a mailing address? If the last option, then perhaps “addrState
” is better. - But avoid gratuitous context.
- What is “
- Came up in discussion: follow common conventions for names.
Clean Code will be continued next time.