On Sat, Aug 12, 2000 at 06:18:08AM +1000, Damian Conway wrote:
> Please, please, please, PLEASE, let us not replicate the debacle that is
> C++'s const modifier!
It doesn't feel like a debacle to me, it feels like it put the control
in the programmers hands. Yes, the syntax is often unweildy -- but IMHO
that's because when one marries the idea of constants to complex data
structures and references, the world becomes an unweildy place.
On the other hand, many of the uses of constants are better-satisfied
by having hidden or inaccessible members. If constants were limited
to `core' perl data types (scalars, lists, arrays and hashes) and
*completely* freezing the data element, that'd be enough for me. I lust
to be able to do things like
if ( $HOME =~ /indiana/ ) {
local $::PI : const = 3; do_trig();
} else {
local $::PI : const = 3.14159...; do_trig();
}
(I'm from Indiana and claim right to use that joke without being
insulting). Constants are good, and I'm damned tired of fixing code like
if ( $PI = 3 ) {
# We're not in Kansas any more, Toto.
}
Constants have a place, and belong in perl.
Now, one may argue that my suggestion was too flexible or too broad.
But the initial proposal left an awful lot of gray areas. If my proposal
is felt to be too unweildy, I don't have a problem with that. Let's
either
o decide where to draw the line, define it cleanly, and say
that more complex usage is better done with objects; or
o permit both complex constants and object-based manipulations
on the practice that TMTOWTDI.
I lean towards the latter (complex constants) myself, but wouldn't
go off and storm the barricades to get it. On the other hand, I
*would* campaign strongly for constant scalars, lists, arrays, hashes
and refs. If the only way to get them meant `completely constant',
ie, no addition or removal or members, no re-orderings, etc, that's
fine -- composition of complex constants with complex vars would let
one do most of what was suggested in my longer posting, and I'd be
happy to say the odder features should be done via object methods.