Good Practices Flashcards

1
Q

What are the 3 problems of “if” statements?

A
  1. Several if blocks may modify the same shared state.
  2. The code blocks may be duplicated.
  3. You have to simulate execution in your head, lik a computer would do.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the alternatives to using “if” statements?

A
  1. Split bundled methods into new methods.
  2. Polymorphism: new classes extending existing ones when the intent is to add new types to an existing entity.
  3. NullObject or Optional type over null passing (Java only)
  4. Simplify an if statement tree into a single inline expression, using for example &&, ||, etc…
  5. Coping strategy: move the if logic further up into the call to avoid duplicating multiple times when dealing with the result.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly