In this chapter, the author discusses issues in writing general control constructs. The author starts discussing boolean expressions and provide following tips:
The author then provides tips to avoid deep nesting by converting nested ifs to if-then-else or to a case statement.
The author then discusses the power of structured programming and its three main constructs:
The author introduces the concept of cyclomatic complexity or control-flow complexity. The author also provides guidelines on how to reduce it.
- Use true and false instead of 1 and 0 for boolean expressions.
- Compare boolean values to false implicitly
- Break complicated tests in partial tests with boolean expressions
- Move the complicated tests completely to a boolean function
- Use decision tables to replace complicated conditions
- Use De Morgan's theorem to simplify boolean expressions
- Use parenthesis to clarify boolean expressions
The author then provides tips to avoid deep nesting by converting nested ifs to if-then-else or to a case statement.
The author then discusses the power of structured programming and its three main constructs:
- Sequence: A set of statements executed in order.
- Selection: It is a construct that allows statements to be executed selectively.
- Iteration: It is a construct that allows group of statements to be executed multiple times.
The author introduces the concept of cyclomatic complexity or control-flow complexity. The author also provides guidelines on how to reduce it.
No comments:
Post a Comment