Notes Flashcards
Boy Scout Rule
Check-in our code a little cleaner than when we checked it out
Rules for Meaningful Names
1) Pronounceable
2) Searchable
3) Class Names are noun or noun phrases
4) Methods are verb or verb phrases
5) Do not pun - same word for two purposes
Rules for Functions
1) They should be small
2) Do One Thing. Note, passing flag argument proclaims a function does more than one thing. Do not do this.
3) Max two or three arguments. If more, it is likely that some of those arguments ought to be wrapped into a class of their own.
4) Command Query Separation
5) Extract Try/Catch Blocks
What is Command Query Separation
Functions should either do something or answer something, but not both
What is a guideline for error handling in a function?
If the keyword try exists in a function, it should be the very first word in the function and there should be nothing after the catch/finally blocks.
What are Good Comments?
1) Legal Comments
2) Informative Comments such as explaining a regex pattern.
3) Explanation of Intent
4) Clarification
5) Warning of Consequence (ex: really long test case)
6) Amplification - amplify line otherwise might be inconsequential.
Name three formatting goals
neatness, consistency, and attention to detail
Describe dependent function formatting
If one function calls another, they should be vertically close, and the caller should be above the callee, if at all possible. This gives the program natural flow.
What is the Law of Demeter?
Objects hide their data and expose operations. More precisely, a method f of a class C should only call the methods of these:
1) C
2) An object created by f
3) An object passed as an argument to f
4) An object held in an instance variable of C
What is a DTO?
Data Transfer Object. Class with public variables and no functions.
What is an Active Record?
A special form of DTO. They are data structures with public variables; but they typically have navigational methods like save and find.
Why wrap third party APIs?
When you wrap a third-party API, you minimize your dependencies upon it. You can choose to move to a different library in the future without much penalty.
What are learning tests?
Writing tests to explore our understanding of third-party code. We call a third-party API, as we expect to use in our application.
The Three Laws of TDD
1) You may not write production code until you have written a failing unit test.
2) You may not write more of a unit test than is sufficient to fail, and not compiling is failing.
3) You may not write more production code than is sufficient to pass the currently failing test.
What’s the most important aspect of a clean test?
Readability. Specifically clarity, simplicity and density of expression. In a test you want to say a lot with a few expressions as possible.