Wouldn't it be great if we could actually fix the problems in the compiler, instead of work around them?

That presumes that this is a problem in the compiler. And I for one, don't think it is. It is a problem with education and attitudes.

For the vast majority of Perl applications, this compiler optimisation is a positive boon. Any application that calls subroutines and methods more than once benefits from this optimisation. And the more times you call those routines, the more you benefit.

The OP outlined a very specific scenario in which this can be perceived as a problem. His example: I've named the subroutine "init" to suggest that this is code that will only be used at the very start of a long program lifetime, which means that the long string buffer will linger around needlessly..

For the vast majority of situations, passing scalars by reference simply isn't necessary or beneficial. But for that small set of cases when you are passing a large volume of data to a used once (or few times) subroutine, then Perl has the facilities to handle that. If people would just use them.

It doesn't make sense to throw away the benefits in the general case, for the sake of avoiding a mildly advanced but perfectly understandable and usable technique, for the degenerate case. Especially not for the sake of a little read-it-once-and-understand-it, education. And certainly not for the sake of some CS dogma.

Relax.

I'm perfectly relaxed thank you. This isn't emotional frustration I'm expressing. It's intellectual frustration.

The same sort you feel when you see some politician, when asked; "Why have you cocked up the economy?", respond with: "First let me say that since I/we came to power there is far less dog poo in our parks and 100,000 more police officers handing out ASBOs and nicking people for seat belt violations...". And never actually answering the question asked.

It would be far better to 'fix' the modules that create the problem, for that tiny subset of all Perl code that are memory constrained, than to penalise the performance of every non-memory constrained Perl app in order to avoid the use of pass-by-reference or aliasing.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^7: No garbage collection for my-variables by BrowserUk
in thread No garbage collection for my-variables by betterworld

Title:
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, details, 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, summary, 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.