Документация
HTML CSS PHP PERL другое

Section 18.9.  Correctness

 
Previous
Table of Contents
Next

18.9. Correctness

Never assume that a warning-free compilation implies correctness.

use strict and use warnings are powerful developments aids, whose insights into the foibles of the typical programmer sometimes border on the magical. It is a serious mistake not to use them at all times.

But, as the examples in the previous guidelines illustrate, they are neither infallible nor omniscient. It may seem counterintuitive, but Perl's extensive list of warnings and strictures can sometimes result in code that is less robust than it otherwise might have been. The comforting knowledge that "use strict will pick up any problems" often engenders a false sense of security, and promotes the illusion that a silent compilation implies a correct compilation.

But no Perl pragma will ever be able to pick out the serious bug in this subroutine:

    sub is_monotonic_increasing {
        my ($data_ref) = @_;
        for my $i (1..$#{$data_ref}) {
            return 0 unless $data_ref->[$i-1] > $data_ref->[$i];
        }
        return 1;
    }

It's foolish not to make use of the very real protections that use strict and use warnings provide. Just don't let those protections make you complacent[*].

[*] By the way, that serious bug was that the conditions under which a return 0 occurs is the wrong way round. The unless should be an if.

    Previous
    Table of Contents
    Next
    © 2000- NIV