Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Why is const x const not a const?

by moritz (Cardinal)
on Jan 22, 2012 at 14:25 UTC ( [id://949256]=note: print w/replies, xml ) Need Help??


in reply to Re: Why is const x const not a const?
in thread Why is const x const not a const?

The original question isn't phrased very carefully, but it does have an interesting core.

Perl has a "peephole optimizer" which evaluates some constant expressions at compile time. You can see that for example here:

$ perl -c -wE '1+1; say "OH HAI"' Useless use of a constant (2) in void context at -e line 1. -e syntax OK

Note that the -c switch means that the code is only compiled, not run. And yet the warning mentions 2 instead of 1+1, so you can see that the expression 1+1 has been evaluated at compile time, not at run time.

The original question could thus be phrase "Why is the expresion "literal" x <literal_number> not constant-folded at compile time, as <literal_number> + <literal_number> is?"

And yes, that's a valid and interesting question

I think if you want a constant use a constant

That's not very convincing. For example if I write '=' x 80, I see immediately that it's 80 equal signs. But if I write '===============================================================================', can you see immediately how many equal signs that are?

The difference in readability is even larger when whitspaces are concerned, ' ' x 20 vs. '                    '. Imagine that being printed out on a sheet of paper. Which one do you find easier to decipher?

Replies are listed 'Best First'.
Re^3: Why is const x const not a const?
by BrowserUk (Patriarch) on Jan 22, 2012 at 15:16 UTC
    That's not very convincing. For example if I write '=' x 80, I see immediately that it's 80 equal signs. But if I write ...

    You can do:

    use constant EQUALx80 => '=' x 80; ...

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Better, name it after its use, rather than its constituents.

      use Readonly; Readonly my $SECTION_SEPARATOR => q{=}x80;

      As Occam said: Entia non sunt multiplicanda praeter necessitatem.

        No. You are absolutely wrong on all counts!

        First. Look at the post I was responding to. The premise was, that it is much clearer from '=' x 80 that there are 80 '=' than if you used

        ==================================================================

        so your 'correction' is wrong in context.

        Secondly, your assumption that that string is a "SECTION_SEPERATOR" is wrong. It cannot be right, because you have no basis upon which to reach that conclusion.

        But mostly, trading use constant for that vacuous, puerile, slow, stupid, braindead, idiotic, stupid -- did I say stupid already? -- worthless, pathetic, fscked-up, oxymoronic piece of crap is ... um .. oh dear, I seems to have run out of appropriate adjectives.

        Update: Oooh. OOoh! I thought of one: fatuous. ( I didn't use that already did I? )


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 10:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found