Prefer highly structured code
It isn’t enough to be disciplined in our specification of
data structures and interfaces: we must also simplify our
code logic. Complicated control structures are as danger-
ous to efficiency and correctness as are complicated data
structures.
When choosing among alternatives in code, we often
have three options:
•
Overloading.
Select among alternative functions based
on the static type of arguments, for example,
f(x)
.
•
Virtual function call.
Select based on the dynamic
type of a class object in a class hierarchy, for example,
x.f()
.
•
Selection statement.
Select on a value with an if-
statement or a switch-statement, for example,
Do'stlaringiz bilan baham: |