I wanted to run this by the QA group before letting it loose on the
language folks.


=pod

=head1 TITLE

"use warnings" by default for all non-one-liners.


=head1 VERSION

Maintainer:     Michael G Schwern <[EMAIL PROTECTED]>
Date:           Mon Sep  4 00:02:12 EDT 2000
Version:        1.0
Mailing List:   [EMAIL PROTECTED]


=head1 ABSTRACT

Warnings can prevent many silly programming mistakes, but are often
overlooked.  "use warnings" should be turned on by default for
non-trivial Perl programs.


=head1 DESCRIPTION

One of the most common newbie questions is "my program didn't print
anything, what's wrong?"  Usually this is a result of a silly mistake,
a mistyped variable name, forgetting to check if a file opened...
More often than not, these simple mistakes would have issued a
warning, if only warnings had been turned on.

Very often, new programmers are unaware of the existance of warnings.
Many tutorials are squeamish about exposing a new user to the
potential deluge of baroque messages which Perl can spew forth.  While
ignorance can be bliss, it is still ignorance.  And silencing a
problem still leaves the problem there.  A program quietly failing can
lead to hours of frustrating debugging.

If a programmer starts their career with warnings off, they may find
themselves overwhelmed with the sheer volume produced by their
existing programs once they decide to turn them on.  Often, this leads
to warnings being quickly switched back off, never to come back on
again.  It is best for a programmer to learn to live with warnings
early on.

Therefore, it is proposed that Perl automatically run each program as
if "use warnings" was placed at the start.

Warnings can get troublesome if you are deliberately writing a quick
and dirty program.  In such cases its no great trouble to write "no
warnings" at the beginning of your program (those who lament the extra
typing, learn to type faster).  In the special case of a one-liner,
which are always quick and dirty, the default will be "no warnings".


=head2 And if I don't like it?

Warnings can always be turned off, either with "-M-warnings" on the
command line, or with "no warnings" at the top of the script, or even
setting PERL5OPT (or Perl 6's equivalent) to "-M-warnings".

An experience programmer will know about these options and customize
their environment as they see fit.  Their decision to ignore warnings
is (hopefully) an educated one.  A novice programmer will likely not
know about these options, but they are not in a position to yet decide
that warnings are unimportant.

The decision to ignore warnings B<must> be an educated one and a
conscious one.


=head2 "use warnings" vs "-w"

"use warnings" has the benefit of being lexically scoped, as opposed
to the global effect of -w.  Using "use warnings" by default rather
than -w means a programmer is only responsible for the sins of his
particular piece of code, rather than those of any libraries and
modules used.

This limited scope of the default warnings should reduce the number of
warnings typically issued.  And since the warnings are about a single
source file, they should be eaiser to find and fix, as only one file
must be delt with.


=head2 Friendliness of warnings.

Perl's current set of warnings, while better than most, aren't exactly
the friendliest creatures in the universe.  Their tone and terminology
can often be disquieting and confusing to new programmers.

If warnings are to be 'forced' upon new programmers, then there must
be an accompanying effort to soften their blow.  This must not be
mistaken for dumbing down of warning messages.  Same content, same
message, but reworded so it doesn't sound like the reader has broken
the law.

This will not be easy.  It will require a reexamination of the huge
numbers of error messages issued by Perl and the conditions in which
they are issued.


=head1 MIGRATION

For the case of most Perl 5 programs which were written without
warnings, they will have no effect other than to print to STDERR.
Usually this is little more than an annoyance, but in special cases,
particularly CGI programs, it can cause the program to abort.  In such
cases, simply placing "no warnings" at the top of the program, or
setting PERL5OPT to '-M-warnings' will return to the Perl 5 behavior
(although it is better to fix what is causing the warnings).

A Perl5->Perl6 translator can trivially call "no warnings" or set
${^WARNING_BITS} to 0.


=head1 IMPLEMENTATION

Unless the -e flag is set, ${^WARNING_BITS} flag will be initialized
to 'all' for the initial scope.  warnings.pm need never actually be
called.


=head1 REFERENCES

=over 4

=item RFC 16 - Keep default Perl free of constraints such as warnings and strict.

This RFC proposes nearly the opposite, that warnings should remain off
by default.

=item L<warnings>

=item L<perllexwarn>

=back

=cut



-- 

Michael G Schwern      http://www.pobox.com/~schwern/      [EMAIL PROTECTED]
Just Another Stupid Consultant                      Perl6 Kwalitee Ashuranse
Maybe they hooked you up with one of those ass-making magazines.
        -- brian d. foy as misheard by Michael G Schwern

Reply via email to