Notes Flashcards

1
Q

Boy Scout Rule

A

Check-in our code a little cleaner than when we checked it out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Rules for Meaningful Names

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Rules for Functions

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Command Query Separation

A

Functions should either do something or answer something, but not both

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a guideline for error handling in a function?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are Good Comments?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Name three formatting goals

A

neatness, consistency, and attention to detail

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe dependent function formatting

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the Law of Demeter?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a DTO?

A

Data Transfer Object. Class with public variables and no functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an Active Record?

A

A special form of DTO. They are data structures with public variables; but they typically have navigational methods like save and find.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why wrap third party APIs?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are learning tests?

A

Writing tests to explore our understanding of third-party code. We call a third-party API, as we expect to use in our application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The Three Laws of TDD

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What’s the most important aspect of a clean test?

A

Readability. Specifically clarity, simplicity and density of expression. In a test you want to say a lot with a few expressions as possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the Build-Operate-Check pattern?

A

Each test is clearly split into three parts. The first part builds up the test data, the second part operates on that test data, and the third part checks that the operation yielded the expected results.

17
Q

What is a good rule for asserts in your tests?

A

The number of asserts in a test ought to be minimized. We want to test a single concept in each test function.

18
Q

Define F.I.R.S.T. clean tests

A

Fast: Test should run quickly.
Independent: Tests shouldn’t depend on each other. One test shouldn’t set up the conditions for the next.
Repeatable: Run in any environment.
Self-Validating: Should have boolean output.
Timely: Unit tests should be written just before the production code that makes them pass.

19
Q

What is the first rule of a class?

A

Classes should be small. We use a responsibility measurement for length.

20
Q

What’s the single responsibility principle?

A

It states, that a class or module should have one and only one reason to change.

21
Q

What is Cohesion?

A

Classes should have a small number of instance variables. Each of the methods of a class should manipulate one or more of those variables. In general, the more variables a method manipulates the more cohesive that method is to its class.

22
Q

What should we be able to do when describing a class?

A

Describe it in about 25 words or less, without using the words “if”, “and”, “or”, or “but”

23
Q

What is the essence of iterative and incremental agility?

A

It is a myth that we can get systems “right the first time.” Instead, we should implement only today’s stories, then refractor and expand the system to implement new stories tomorrow.

24
Q

Describe starting “naively simple”

A

We can start a software project with a “naively simple” but nicely decoupled architecture, delivering working user stories quickly, and then adding more infrastructure as we scale up.

25
Q

Feature Envy

A

The methods of a class should be interested in the variables and functions of the class they belong to, and not the variables and functions of other classes. When a method uses accessors and mutators of some other object to manipulate the data within that object, then it envies the scope of the class of that other object. It wishes it were inside that other class so that it could have direct access to the variables it is manipulating.

26
Q

Selector Arguments

A

Type of argument that is used to select the behavior of the function.

27
Q

Describe use of explanatory variables

A

One of the more powerful ways to make a program readable is to break the calculations up into intermediate values that are held in variables with meaningful names.