On Tue, Oct 30, 2001 at 04:29:15PM +1100, Damian Conway wrote:
> 
>    > > I'd do that like so (using Larry's preferred syntax):
>    > [...]
>    > >         method INIT ($idval) { $.id := $idval }
>    >
>    > Hm... that looks to me like a regular ":="; is it?
> 
> Yep.
> 
> 
>    > If so, what good is "is const" if you can override it with
>    > a ":="? Am I missing something?
> 
> That's a binding, not an assignment.
> 
> C<is const> means: "Once declared cannot be *assigned* to".
> 
> But that doesn't mean one can't *bind* a new value to the variable
> (which would retain its C<const>-induced unassignability after the binding).

I understand that. I guess what I'm saying is, from a conceptual
standpoint, isn't it misleading to say that "class Filesystem provides
a constant called MAXPATHLEN, which is 2048", but then to have
the class override that and change it to 1024?!

I understand that we can wag a finger at the person who does this
and tell them that they will have bad luck for seven years.

On a meta-topic, I see many answers in this list (especially from
Larry and Damian) coming back in the form, "well, yeah, but
that's not how it works internally."

I suggest that Perl's internals are very interesting, and certainly
very important, but features such as constants instance variables
have meaning to programmers, and if their application in Perl does
not conform to expectation, programmers are likely to have a
rougher time.

> Consider the following Perl 5:
> 
>         # CREATE CONSTANT
>         *constant = \7;
>         print "$constant\n";
> 
>         # TRY TO ASSIGN (THROWS EXCEPTION)
>         eval { $constant = -7 } or print $@;
>         print "$constant\n";
> 
>         # TRY TO REBIND (WORKS FINE)
>         eval { *constant = \-7) } or print $@;
>         print "$constant\n";

Yep, but in Perl5, this was never very clean or obvious to the
casual programmer. Constants have been coming of age in Perl,
and they're kind of scary if they're not constant.

-- 
Aaron Sherman
[EMAIL PROTECTED]             finger [EMAIL PROTECTED] for GPG info. Fingerprint:
www.ajs.com/~ajs        6DC1 F67A B9FB 2FBA D04C  619E FC35 5713 2676 CEAF
  "Write your letters in the sand for the day I'll take your hand
   In the land that our grandchildren knew." -Queen/_'39_

Reply via email to