Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Extreme Programming in Perl Robert Nagler phần 6 doc
Nội dung xem thử
Mô tả chi tiết
checking, and printing are contained in separate routines. Each routine
is responsible for one and only one behavior.
• The localtime and gmtime calls are now in the correct order. This
defect in the original version only became apparent to me when I
separated the two output lines.
• Argument type validation is consistent, because it has been isolated
into a single routine ( plan arg assert) that is used for all three
parameters. Several new cases are caught. For example, passing undef
to tests or passing both tests and test (deprecated form) is not
allowed.
• Carp::croak unrecognized directive warning is printed once instead of
a warning per unrecognized directive. The check for unrecognized
directives still does not fail fast (croak or die). I would have liked
to correct this, because passing an invalid directives to plan probably
indicates a broken test. However, the broad user base of Test makes
this change infeasible. Somebody may be depending on the behavior
that this is only a warning.
• Two temporary variables (@todo and $x) were eliminated by using a
functional programming style. By avoiding temporary variables, we
simplify algorithms and eliminate ordering dependencies. See the It’s
a SMOP chapter for a longer example of functional programming.
• $planned was eliminated after $ TODO was converted to a reference.
$planned is known as a denormalization, because it can be computed
from another value ($ TODO in this case). Normal form is when data
structures and databases store the sources of all information once and
only once.
• plan print writes a single string. The seven calls print were unnecessary duplication. I often use logical operators instead of imperative
statements to avoid the use of temporary variables, which are another
form of duplication (denormalization).
• The return value from plan is better represented as an empty return,
because it handles list and scalar return contexts correctly. This is a
subtle point about return, and it actually involves an interface change.
The following use assigns an empty list:
Copyright c 2004 Robert Nagler
All rights reserved [email protected]
76