Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Auto Increment "magic" Inquiry

by brusimm (Pilgrim)
on Jan 04, 2007 at 21:53 UTC ( #593029=note: print w/ replies, xml ) Need Help??


in reply to Re: Auto Increment "magic" Inquiry
in thread Auto Increment "magic" Inquiry

Solo, The second part of your post is what I am attempting to discover here. The explanation.

Since my co-worker can seem to accurately predict the printed results, it seems to defy everything (Or is it pure luck?) I've read in the reference materials that I quoted in my posting, that are available online. That's why I'm thinking someone may have an insight as to how this can happen on my system in such a consistent fashion. If not, so be it, but I was hoping to at least have a better understanding of it on my system, as it's acting.

Thank you Solo


Comment on Re^2: Auto Increment "magic" Inquiry
Re^3: Auto Increment "magic" Inquiry
by roboticus (Canon) on Jan 04, 2007 at 22:22 UTC
    brusimm:

    It's consistent because Perl will generate the code the same way each time you compile it. However, another version of Perl may generate slightly different code for the same sequence.

    For example, suppose you have the statement $j = $i++ + $i++;. It's perfectly acceptable for perl to implement it as:

    $temp_1 = $i; $temp_2 = $i; $j = $temp_1 + $temp_2; $i = $i + 1; $i = $i + 1;
    and it's also acceptable for it to implement it like:

    $temp_1 = $i; $i = $i + 1; $temp_2 = $i; $i = $i + 1; $j = $temp_1 + $temp_2;
    (Other implementations are also possible...) So while any particular perl compiler will be consistent from run to run, and program to program, different perl compilers (version, platform, vendor, etc.) are free to do it another way.

    Your co-worker appears to know which way it's implemented on your perl compiler.

    roboticus

Re^3: Auto Increment "magic" Inquiry
by jbert (Priest) on Jan 05, 2007 at 12:46 UTC
    Things can be entirely consistent and predictable and yet not reliable.

    What?

    When the docs say you can't rely on something, it means that the behaviour isn't part of the public interface. It's liable to change without notice.

    In fact, docs are more likely to say that about predictable things, since those are the very behaviours which users are likely to assume are reliable.

    This sort of thing is more of a problem when you do too much learning through experimenting. You can't tell whether things you learn via experimentation are defined behaviour or an accidental side-effect of implementation, so you need to check them against the docs before relying on them.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-07-23 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls