Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found