Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I have some huge worries about this.

I know why you want it. Ruby uses this (among other things) to support $` etc lazily without bugs. If you don't use the feature, you don't pay for it, and if you use it, you only pay for as much of it as you use. (By contrast Perl's hack with a global flag means that if you use it, you pay like heck.)

However if you try to use copy on write with magic in Perl, you will get serious bugs from the fact that magic and local have a well-developed distaste for each other. This would give efficient $` etc. But only at the cost of introducing weird bugs involving mixing matches and local variables.

Beyond that, any language with copy on write is best of (IMHO) using it aggressively and thinking through carefully the desired semantics. The reason to use it aggressively is that marking things copy on write is an excellent way to save lots of work on potentially expensive operations like assigning data to variables, and also it exercises your copy on write logic to catch any bugs. Both are good. (It is too easy to accidentally ignore copy on write somewhere and you want to catch that. Just like how the local and magic mechanisms in Perl ignore each other...) The reason to think about the semantics is that for things like argument passing there can be subtle differences between pass by value, pass by reference, and passing by aliasing with copy on write. Semantically the first and third resemble each other, but with profound performance implications. The second, in the right environment, can superficially look a lot like the previous two but with gotchas to be aware of.

For instance in comparing Ruby and Perl, a key point that is often missed is that in Ruby assignment is by reference, not value. Given that most operations in Ruby create new copies, this works out fairly naturally. But beware!

a = "Hello"; b = a; b << ", World"; # Note: += would not do this! puts a;
I think this is a gotcha which is worth pointing out...

Anyways Perl has a well-established semantic model. If it was to add copy on write, it should think carefully on how to update that model...

In reply to Re (tilly) 1: Don't have a COW? Get one! by tilly
in thread Don't have a COW? Get one! by japhy

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2020-07-14 23:30 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found