Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Constant names come into conflict with Perl style?

by dmitri (Priest)
on Feb 07, 2007 at 19:56 UTC ( [id://598868]=note: print w/replies, xml ) Need Help??


in reply to Re: Constant names come into conflict with Perl style?
in thread Constant names come into conflict with Perl style?

That might be a fine module and I'll check it out, but it does not answer the question posed: is this commonly accepted practice of using upper-case constant names directly clash with another commonly accepted practice of not naming subroutines in all caps?
  • Comment on Re^2: Constant names come into conflict with Perl style?

Replies are listed 'Best First'.
Re^3: Constant names come into conflict with Perl style?
by reyjrar (Hermit) on Feb 07, 2007 at 20:20 UTC

    constant.pm actually is creating subroutines. I picked up a copy of Perl Best Practices, in which Damian Conway recommends Readonly.pm for the exact reasont that you stated.

    I'm not sure what you're looking for here. The "best practices" are constantly evolving as new and interesting modules enter the fray. Program the way that makes sense to you. Following best practices is encouraged but not required and not always the best solution.

    Typically uppercase subroutines signify that they'll be called by some internals. This isn't set in stone as heredocs and labels typcially use all caps as well. Generally you need to establish context to determine how in accordance with best practice a particular piece of code is.

    It makes sense for a constant to be a variable, which is why I like Readonly. I have run into issues where a Readonly array is actually useful. It doesn't happen daily, but when it does rear it's head, I like to address it with Readonly.pm rather than some copying hack.

    If you want to get into the philosophy of when and where to hold down shift, perhaps starting a thread on Meditations would be a better fit.

    -brad..
      Whether constants should have a sigil is also subject to philosophical debate: for instance, DEBUG just does not look like a potential lvalue, while $DEBUG does.

      As for placing this into "Meditations," I am not sure that a question this short belongs there. I am simply asking for opinions, as I think I have stumbled upon a contradiction in Perl's conventions.

        for instance, DEBUG just does not look like a potential lvalue, while $DEBUG does.

        ++. I've never looked at it that way, and I like it. Thanks.

        That said, Perl6 seems to use the construct:

        my $foo is readonly = 12;
        so we will have the issue come up again: $foo looks like an lvalue, but isn't. Further, I think we will be able to define sub's as rvalues, further confusing the issue. ;-)

      "It makes sense for a constant to be a variable"

      Reading that made me dizzy. ;) Seriously though thats a bit counter intuitive sounds like "it makes since for 4 to be 2." Not trying to start a debate, just suggesting maybe you find a different phrase, maybe "it makes sense to be able to mark variables as constant", though that still has the same ring to it. Having neither used Readonly or constant I guess I'll be quiet.


      ___________
      Eric Hodges

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://598868]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-25 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found