Nate the prolific Perl6 RFC producer and commentator wrote:
> I don't think suggesting that we eliminate globals altogether is a good
> or feasible idea. It's an unnecessary crutch. They are useful in many
> circumstances.

  So here's my order of preference:

1) Eliminate dynamic variables entirely.

2) Eliminate dynamic variables from default Perl, but allow their use
with a pragma.

3) Provide a new strict pragma to disable dynamic variables.  (Note
that I have an ulterior motive, here; strict is the de-facto standard
for module writing.  If I get this into strict, then everybody will
feel obligated to write their modules in this style. :)  Of course,
module writers are supposed to be good enough to not use unnecessary
crutches, right?)

CONTEXT ALERT:  All of this is still optional to RFC 106, which can
provide for making lexical variables the default without having to do
anything to dynamic variables.  Don't have a cow if you were worried
about that.

> I think this is shaping up to be a really good proposal. Here's what I
> hear:
>
>   1. All variables are liberally lexically scoped by
>      default. Either scope them package-wide or do the
>      nearest block idea.
>
>   2. You can explicitly scope variables with my or our.
>
>   3. Global variables can still be declared with 'use vars'.
>
>   4. Dynamic keywords (like local) still only work on
>      global variables.
>
> Sound accurate?

  Everything except #4.  I explicitly believe in allowing dynamic
assignment on lexical variables.  Way back before this list, when the
first version of RFC 6 came out, Tom Christiansen commented, "One
could even make Chip happy and allow one to C<scopetemp> [one of many
proposed new names for local()] a lexical."  I'm not saying Tom was
behind the idea, but it is a possibility, and I'm behind it.
Apparently, Chip (the same one who started Topaz, I presume?) was,
too, at some earlier point in Perl history.

> Exactly how point #1 is implemented can be left till
> later, just as long as this:
>
>    $x = 1;
>    {
>       $y = $x + 1;
>    }
>    print "$y";
>
> Works without any predeclarations.

  Agreed.  Implementation suggestions (both of them) will be relegated
to the implementation section.

> P.S. I meant "package-wide" in the previous email. The package should
> always be the outermost logical container, I think.

  But packages can span multiple files.  This boogers up lexical
scoping.  Two different files should both be able to plop
subroutines/methods (and, yes, dynamic variables if they still exist)
into a package, but they need to depend upon their _lexical_ variables
not clashing.  Otherwise, some of the more esoteric Perl modules might
not be able to function (those that deliberately tweak the contents of
other packages).


J. David

Reply via email to