in reply to Re: use constant for strings (unary plus)
in thread use constant for strings

personally, i don't like the unary plus. how does it make things less ambiguous? "plus" means "not an expression"? it's not clear. besides, we have sigils to remove ambiguity, anyway. i'd recommend &WISCONSIN, or if you're afraid of side effects (which won't occur with constants,) use &WISCONSIN(). more to write, but leaving less to the imagination.

~Particle *accelerates*

Replies are listed 'Best First'.
Re^3: use constant for strings (unary plus)
by Aristotle (Chancellor) on Apr 18, 2003 at 21:00 UTC

    I don't want to use the sigil simply because it disables the prototype and thus the constant-ish nature as mentions of the "constant" become regular runtime function calls (otherwise they'd be substituted at compile time). I might as well just use a variable.

    Seeing as the unary plus doesn't work here, the next best thing I'd prefer would be (WISCONSIN) - with the parens following it looks quite awkward IMHO.

    I like the unary plus in other situations and use it lots though - f.ex

    map +(foo($_, "bar"))[3], @baz;
    where I would otherwise be forced to use curlies
    map { foo($_, "bar"))[3] } @baz;
    or another extra pair of parens.
    map((foo($_, "bar"))[3], @baz);
    I don't like either of the latter two, though I realise quite a few people here will disagree. I think the last one at least is certain not to win any prizes for beauty..

    Makeshifts last the longest.

      Out of interest, why do you favour map +...., @.. over map{ ... } @..?


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.

        Because the map +expr, syntax is great whe you have exactly one expression - I really dislike having a block around when it is so completely superfluous. The concepts conflict - applying an expression or applying a block. This allows the right idiom to be maintained. Its also concise which is a virtue.

        It also happens to be a bit cheaper since you don't get the overhead of a block.

        What he said.

        Makeshifts last the longest.

Re^3: use constant for strings (unary plus)
by tye (Sage) on Apr 18, 2003 at 19:39 UTC
    i'd recommend &WISCONSIN, or if you're afraid of side effects (which won't occur with constants,)

    Then I guess you've never noticed how "constants" are implemented by default when one uses h2xs. I've seen &CONST cause warnings in real code because of that.

    But I don't use &CONST because I know it passes @_ to the CONST subroutine and I don't want whoever ends up maintaining my code wondering why I'm passing @_ in. Just because it (usually) works, doesn't mean it makes sense. (:

                    - tye