in reply to constant confusion

Thanks for bringing that to our attention. However, I don't use constant anyway. I don't like the "filehandle-ish" look of the constants; I find it more perlish to just use normal variables, but with uppercase names. Yes, this way they can be modified, but everybody should know they shouldn't :).

Replies are listed 'Best First'.
Re: Re: constant confusion
by Mr. Muskrat (Canon) on Apr 23, 2003 at 16:22 UTC

    Constants must start with a letter (or underscore) but there is nothing that says that they must be uppercase.

    "The use of all caps for constant names is merely a convention, although it is recommended in order to make constants stand out and to help avoid collisions with other barewords, keywords, and subroutine names. Constant names must begin with a letter or underscore. Names beginning with a double underscore are reserved. Some poor choices for names will generate warnings, if warnings are enabled at compile time."
      Yeah, but that statement is a bit silly. Using all cap names doesn't avoid collision with other barewords. Typical barewords found in Perl programs are uppercase: file and directory handles. The other major category of barewords are in titlecase: package names. Barewords as in unquoted strings I only find in the student books of the Perl courses of HP Education.

      Avoiding collisions with subroutine names? Come again? You know which subroutine names you are using, don't you? Besides, what if you do use subroutines, aren't you in grave danger of colliding with other subroutine names? No, of course not. It's not a problem for the set of subroutines in a program, and won't suddenly be a problem if you use lowercase constants.

      Leaves us collisions with keywords. Well, you know which keywords there are, so it's easy to avoid them. The only potential problem you have is when you upgrade perl, new keywords might be introduced. Of course, you already have a problem because subroutine names can collide as well. But how common are new keywords in new versions of Perl anyway? In the last couple of yours, new keywords are our and lock, both introduced in 5.005. But in 5.005, we also saw the birth of INIT and in 5.6.0, CHECK was introduced. So, using all caps is as likely to cause a collision as to use all lowercase.

      If you want to reduce the chance of collisions, you'd use names starting with a lowercase letter, and having one or more uppercase letters in them as well.

      Abigail

        you'd use names starting with a lowercase letter, and having one or more uppercase letters in them as well.
        I reallyHateThatStyle, evenMoreSoThan PlainStudlyCaps. Yuck.

        Makeshifts last the longest.

      Yes, but I find constants even weirder when just using lowercase. I find it easier to maintain code if I stick to the usual sigils, uppercase FILEHANDLEs and lowercase sub_names. Using constant would somewhat spoil that scheme. Or maybe I'm just not flexible enough :)

Re^2: constant confusion (filehandles be lexicals)
by Aristotle (Chancellor) on Apr 26, 2003 at 03:04 UTC
    All my file handles these days are lexicals, as they should be. That means all-uppercase identifiers are free for the taking, and constant gets them.

    Makeshifts last the longest.