On 7/18/05, Uri Guttman <[EMAIL PROTECTED]> wrote:
> >>>>> "KS" == Kripa Sundar <[EMAIL PROTECTED]> writes:
> 
>   KS> Dear Uri,
>   >> [...] subs can come into existance any time and be
>   >> handled by AUTOLOAD and such. so there is no easy compile time way to
>   >> check that at the moment. [...]
> 
>   KS> It is the same principle as for any other stricture.  The user is
>   KS> asking perl to flag some *legal* usage as being unacceptable for
>   KS> her/his purpose.
> 
> but perl can't divine if subs exist before they are called because some
> module may do things differently. just look at AUTOLOAD.

So sometimes Perl gets it very wrong.  That's OK, if people choose
to turn on optional warnings, they are choosing the new behaviour.

>   KS> For the user who does not want dynamically defined routines, it
>   KS> should be trivial for the compiler to honour a suitable pragma
>   KS> (say, "use strict sub_definitions") and die if it sees that there
>   KS> are some subroutine invocations without any compile-time
>   KS> definitions.
> 
> but will that honor modules that are used? that pragma can be lexically
> scoped but it still is an issue. what about calling something in BEGIN
> but before it is compiled? perl can't detect that until it tries because
> something else in the BEGIN block could define the function.

So?  You choose to turn on a pragma that breaks on valid code.
Your choice, and you'll catch the gotchas in pretty fast in
development.

>   KS> An invocation before a declaration is legal Perl, but gets flagged
>   KS> under "use strict subs".  An invocation without a definition should be
>   KS> equally easy to flag (although, of course, perl would have to wait
>   KS> until the end of compilation to do so).
> 
> if you invoke with foo() then you don't get that strict problem. the
> issue is how can you tell a sub will be defined when a call to it is
> compiled. if you call subs later in the source file, they won't be
> defined at the time of the call being compiled, so that fails. you can
> then force predeclaring of subs in that case (like c) but most perl
> hackers will hate that. i know what you want but i don't see any easy
> way to do it that will satisfy most people.

Then most Perl hackers will not use a stricture like this.  Though I
think that more will than you realize.

I happen to like the idea of having this there as an option.  Right
now it isn't an option, so if you want to catch subroutine typos
the best that you can do is declare functions like this:

  my $foo = sub {
    ...
  };

and then call them with:

  $foo->(@args);

which will make everyone else want to kill you.

Cheers,
Ben
 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to