Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^10: Pre vs Post Incrementing variables

by JavaFan (Canon)
on Sep 13, 2010 at 09:41 UTC ( [id://859963]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Pre vs Post Incrementing variables
in thread Pre vs Post Incrementing variables

But, if I pass sub-expressions to a function, I expect to get references to (temporary) variables containing the results of those sub-expressions.
Then your expectation is wrong. Perl doesn't guarantee this. And if you want a regular language, Perl isn't for you.
It is only in the case of pre-increment expressions (and a few other similar anomalies), that the function receives a reference to the target of the sub-expression, rather than a reference to the result of it.
Yeah. It's called lvalues. Just labelling them anomalies doesn't make them bugs. As I said, if you want a regular language, don't use Perl.
And the clincher that this is a bug
And the ID of your bug report is?
This has no such justification.
The justification is optimization. (Just as the orginal reason for C). Not in keystrokes, but in execution. Here the optimization is that by returning an alias, it saves creating a new SV. If you don't want the alias, create a copy.
  • Comment on Re^10: Pre vs Post Incrementing variables

Replies are listed 'Best First'.
Re^11: Pre vs Post Incrementing variables
by BrowserUk (Patriarch) on Sep 13, 2010 at 14:16 UTC
    If you don't want the alias, create a copy.

    It not getting an alias that is the problem is it. It's getting the same alias for two or more different sub-expressions.

    And the ID of your bug report is?

    There is no point in raising one. Because the problem description would be the OP, and that would be dismissed on the basis of this. Which is underpinned by the passage I quoted here.

    The justification is optimization. ... it saves creating a new SV.

    And so we come full circle. We're back to "Perhaps the most short-sighted and pervasive premature optimisation ever."

    That saving of the creation of a new SV, in the limited cases of pre-increment and assignment operators only--hardly so pervasive in code that it requires optimising--creates the situation that means many useful behaviours are denied the programmer. Along with the resultant contradiction of the principle of least surprise.

    It's not going to change now, And I didn't set out to make a case for it to change now. Only to document how it came about in the first place. And then support my assertion that the quoted phrase above is indeed the source of the chain of causality.


    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found