Clean Code | Set 1 Questions and Answers with 100% Correct
Answers | Latest Version
Question 1.
What are the guides to good naming?
Correct Answer: 1. Use intention-revealing names
2. Avoid disinformation
3. Make meaningful distinction
4. Use pronounceable names
5. Use searchable names
6. Avoid encodings
7. Avoid mental mapping
8. Pick one word for a concept, and stick with it
9. Avoid have one-word concept mean more than one thing
10. Use solution-domain names (CS terms)
11. Use problem-domain names for non-programmers
12. Add meaningful contexts
Question 2.
What does it mean to be intention-revealing?
Correct Answer: Allow naming of variables/classes/methods to answer the
question the code-reader will have when going through the logic
Question 3.
Give an example of being misleading in naming
Correct Answer: If you have in general, a group of accounts, and name it:
"accountList" This can be misleading because it can apply that this is
List<Account>, when the variable could be not a List type at all. It is better to
name it as: "groupOfAccounts" "accounts"
Question 4.
What does it mean to have names that have meaningful distinctions
Correct Answer: When you write code to solely satisfy the compiler ex) a1, a2..
aN You want to make distinct calls and avoid making similar names to confuse
the reader. Sometimes you need to reduce your abstractions or distinctively
name them.
Question 5.
What does it mean to avoid mental mapping?
Correct Answer: Reader shouldn't have to cache in his/her head the abstractly
named variable throughout reading the logic. Avoid making the reader think:
"what was this {BAD_VARIABLE_NAME} again? "
, Question 6.
What does it mean to have "good" context?
Correct Answer: "state" Does this mean it will have values like "GA", "IL", "NY"
OR does this mean the state of the application? Give more context to ambiguous
names. Also, don't add too much context.
Question 7.
What are guides for good functions?
Correct Answer: 1. Smaller lines (Indent level should not exceed 1-2)
2. Do one thing
3. One level of abstractions per function
4. Use descriptive names (don't be afraid to name things long)
5. Should avoid having more than 2 arguments
6. It's okay to convert multiple arguments to one argument object
7. Variable argument are considered as one argument
8. Make your function names have a verb and keywords that give clear context
9. Have no side effects
10. If your function must change the state of something, have it change the
state of its owning project
Question 8.
What does it mean to have a function do one thing?
Correct Answer: If a function does only the steps that are one level below the
stated name of the function, then the function is only doing one thing
Question 9.
We want to be able to read the program as though it were a set of steps, each of which is
describing the current level of abstraction and referencing subsequent steps at the next
level down.
Correct Answer: The step down rule
Question 10.
Single Responsibility Principle
Correct Answer: a class/method should have only a single responsibility (i.e.
only one potential change in the software's specification should be able to affect
the specification of the class)
Question 11.
Open/Closed Principle
Correct Answer: Classes should be open for extension but closed for
modification.
Answers | Latest Version
Question 1.
What are the guides to good naming?
Correct Answer: 1. Use intention-revealing names
2. Avoid disinformation
3. Make meaningful distinction
4. Use pronounceable names
5. Use searchable names
6. Avoid encodings
7. Avoid mental mapping
8. Pick one word for a concept, and stick with it
9. Avoid have one-word concept mean more than one thing
10. Use solution-domain names (CS terms)
11. Use problem-domain names for non-programmers
12. Add meaningful contexts
Question 2.
What does it mean to be intention-revealing?
Correct Answer: Allow naming of variables/classes/methods to answer the
question the code-reader will have when going through the logic
Question 3.
Give an example of being misleading in naming
Correct Answer: If you have in general, a group of accounts, and name it:
"accountList" This can be misleading because it can apply that this is
List<Account>, when the variable could be not a List type at all. It is better to
name it as: "groupOfAccounts" "accounts"
Question 4.
What does it mean to have names that have meaningful distinctions
Correct Answer: When you write code to solely satisfy the compiler ex) a1, a2..
aN You want to make distinct calls and avoid making similar names to confuse
the reader. Sometimes you need to reduce your abstractions or distinctively
name them.
Question 5.
What does it mean to avoid mental mapping?
Correct Answer: Reader shouldn't have to cache in his/her head the abstractly
named variable throughout reading the logic. Avoid making the reader think:
"what was this {BAD_VARIABLE_NAME} again? "
, Question 6.
What does it mean to have "good" context?
Correct Answer: "state" Does this mean it will have values like "GA", "IL", "NY"
OR does this mean the state of the application? Give more context to ambiguous
names. Also, don't add too much context.
Question 7.
What are guides for good functions?
Correct Answer: 1. Smaller lines (Indent level should not exceed 1-2)
2. Do one thing
3. One level of abstractions per function
4. Use descriptive names (don't be afraid to name things long)
5. Should avoid having more than 2 arguments
6. It's okay to convert multiple arguments to one argument object
7. Variable argument are considered as one argument
8. Make your function names have a verb and keywords that give clear context
9. Have no side effects
10. If your function must change the state of something, have it change the
state of its owning project
Question 8.
What does it mean to have a function do one thing?
Correct Answer: If a function does only the steps that are one level below the
stated name of the function, then the function is only doing one thing
Question 9.
We want to be able to read the program as though it were a set of steps, each of which is
describing the current level of abstraction and referencing subsequent steps at the next
level down.
Correct Answer: The step down rule
Question 10.
Single Responsibility Principle
Correct Answer: a class/method should have only a single responsibility (i.e.
only one potential change in the software's specification should be able to affect
the specification of the class)
Question 11.
Open/Closed Principle
Correct Answer: Classes should be open for extension but closed for
modification.