03 - Write Simple units of code Flashcards

1
Q

What should be the maximum number of branch points?

A

4

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

How should we reduce the number of branch points?

A

By splitting complex units into simpler ones; and if possible avoiding complex units all together.

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

What is the benefit of minimizing branch points within a unit?

A

It makes a unit easier to modify and test.

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

What is a branch point?

A

A Statenebt where excecution can take more than one direction, depending on a condition

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

What sort of code counts as a branch point?

A
if
case
?
&&, ||
while
for
catch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Let’s say I have this code:

public int foo(int myNumber) {
    if (myNumber > 10) {
        return int + 5;
    }
		if (myNumber < 20) {
        return int + 5;
    }
    return int;
}

And I decide to reduce the number of lines:

public int foo(int myNumber) {
    if (myNumber > 10 || myNumber < 20) {
        return int + 5;
    }
    return int;
]

Did I just decrease my branch points?

A

No. Although you reduced the number of lines, if counts as a branch point and so does ||. The number of branch points remains two.

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