> How about any variable created in UPPER case is a constant?
Well, Perl does something similar now, just that they're not readonly.
But as everyone knows messing with @ISA, %ENV, BEGIN, FETCH, etc, etc,
etc will definitely alter your program.
Do we really need constants in Perl? I've always wondered why constants
are necessary. For one thing, I think the name is bad, since it implies
they must be readonly and static. I think "definitions" or "specifiers"
is better.
I think a set of rules like this:
1. Anything in all-UPPER case is reserved for Perl
2. But do whatever you want
Is an argument for removing "use constant" and constants altogether. If
a person wants to do something like this in Perl 6:
$STDOUT = $myfileobject;
print "Hello, world!\n";
$O{RDWR} = 42;
open sys "/etc/motd", $O{RDWR}|$O{CREAT}, 0644;
Let them! They probably know what they're doing. And if they don't, then
they should have read rule #1.
And, if you want to roll your own "definitions", you can do so in
modules. They just won't be readonly, but this is something that can be
circumvented by simple accessor functions:
my $f = new Custom::FileModule;
print "The default file is ", $f->constant('DEFAULT_FILE');
Which is probably similar to what you'd end up doing if you're writing a
big site-wide module anyhow. A big problem with NOT doing it this way
(and just creating $ALLCAPS scalars/hashes/etc) is that if Perl 6.2.1
decides $PI is going to be "Paragraph Indicator", you're in big trouble.
Anyways, I'm not really strongly-opinionated, but I do think that the
syntax has to be extremely simple, like what Larry suggested earlier in
the thread:
my num $PI : constant = 3.1415926;
my int @FIB : constant = (1,1,2,3,5,8,13,21);
I disagree with Steve Simmons; I don't think creating huge struct-like
hashes is the way to go. Just make the variable readonly. "Perl isn't
really a very paranoid language anyways" (or something like that). :-)
-Nate