Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: What is the difference between the constant construct in Perl and the Readonly construct in Perl?

by BrowserUk (Patriarch)
on Jul 06, 2006 at 02:07 UTC ( [id://559467]=note: print w/replies, xml ) Need Help??


in reply to What is the difference between the constant construct in Perl and the Readonly construct in Perl?

Besides all the optimisation features of constant so carefully omitted by the Readonly docs (as noted by diotalevi++), another of things I especially like about

use constant SYMBOL => 123;,

is that my constants don't look like variables.

All the hyperbole about Readonly exported variables being immutable makes me think of nothing more than the old saying about constants that aren't and variables that won't. I cannot imagine why anyone would want their constants to look like variables?

The minor inconvenience of using (s)printf in order to embed the values of constants into strings is actually a plus. If I define pi in my program, I'm gonna define it to the full accuracy of whatever math I'm using supports. For standard floats that's use constant PI => 3.1415926535897931; in order to use the best accuracy in my calculations. But if I'm going to display pi, I'm probably going to settle for showing 3 or 4 decimal places. (s)printf are the tool for this, so it works out great.

Another ill-thought through solution to a non-problem foisted on the world under the title of a best practice.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: What is the difference between the constant construct in Perl and the Readonly construct in Perl?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: What is the difference between the constant construct in Perl and the Readonly construct in Perl?
by rodion (Chaplain) on Jul 06, 2006 at 15:19 UTC
    For standard floats that's use constant PI => 3.1415926535897931;

    I can't help but comment, even if it's OT, obscure, and makes absolutely no practical difference. It's still, ever so slightly, wrong It should be

    PI => 3.1415926535897932;

    There, I feel better.

    By the way, I thought your closing, "Another ill-thought through solution to a non-problem foisted on the world under the title of a best practice." was a nice expression of opinion, both precise and articulate (though not at all one with which I agree.) However, if one doesn't read it carefully, it can remind those in the US of a typical american rant, and there's now doubt those who took it that way. (Over here, we're little familliar with the articulate verbal sparring of Gladsone and Disraeli, or their decendants.) I'm just offering clarification; I'm not suggesting you do anything differently.

      PI => 3.1415926535897932;

      Ah but...

      printf "%19.17f\n", 3.1415926535897932;; 3.14159265358979310

      Blame IEEE 754, not me :)

      ... articulate verbal sparring of Gladsone and Disraeli ...

      I wish. Baldrick maybe ;)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: What is the difference between the constant construct in Perl and the Readonly construct in Perl?
by Anonymous Monk on Jul 06, 2006 at 02:55 UTC
    I cannot imagine why anyone would want their constants to look like variables?
    Because variables Do What We Want without constant bletcherosity like the $foo{+BAR} hack? Which is buried way down in the bugs section of perldoc constant where nobody is going to see it, by the way. Seriously, someone ought to collect up all the "How do I do X with a constant?" FAQs and answer them right up at the top of the documentation.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found