Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^5: No garbage collection for my-variables

by BrowserUk (Patriarch)
on Sep 17, 2008 at 00:06 UTC ( [id://711837]=note: print w/replies, xml ) Need Help??


in reply to Re^4: No garbage collection for my-variables
in thread No garbage collection for my-variables

If that function is called in a non-void context, it is returning the result of the "debug statement", which seems more than a little artificial.

If the function is ever called in a non-void context, it will be because it returns something useful. If the return statement (or the fall-off-the-end expression) is omitted, then the function isn't going to work the way it is intended anyway, so any other error is academic. Just another justifiction I'm afraid.

Plenty of languages use pass-by-reference, and thousands of programmers and millions of programs use it every day without dire consequences.

Designing interfaces around performance optimizations and memory management oddities just doesn't seem right to me.

You seem to be saying: Oh, I mustn't use this language feature, because that would make my code more efficient and that would be an optimisation and it might be premature!

Why does Text::CSV_XS exist? Or the XS version of List::Util? Or ...

It's changing your transatlantic flight path to take full advantage of (or avoid) the gulf stream. It's shutting off the fuel supply to the injectors when the engine is on overrun. Removing your roof rack when you aren't using it.

Perl is a context sensitive language, it is a uniquie and powerful defining feature. Perl programmers need to be aware of it, understand it and use it. Pretending it doesn't exists, or running scared of it you might as well use VB.

It drives me nuts. I use Perl, because I like the language. But there are people around here won't use map or grep; or statement modifiers; or unless or until. They eshew aliasing; context sensitivity; autovivification; the implicit variables: it and these. They want everything OO; will jump through hoops creating singleton classes, "to avoid globals" and end up with nothing more than lexically-scoped globals (eg. our). Use ReadOnly variables as constants instead of constants.

Why bother using Perl?


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.
  • Comment on Re^5: No garbage collection for my-variables

Replies are listed 'Best First'.
Re^6: No garbage collection for my-variables
by moritz (Cardinal) on Sep 17, 2008 at 07:19 UTC
    ou seem to be saying: Oh, I mustn't use this language feature, because that would make my code more efficient and that would be an optimisation and it might be premature!

    No, I'm not. I'm merely saying that ... well, what I said. Everything else was interpretation from you.

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

    Why does Text::CSV_XS exist? Or the XS version of List::Util? Or ...

    The XS version of List::Util is a perfect example of where the interface is not affected by performance optimizations at all. As a programmer I don't even know if the pure perl or the XS version is actually loaded, which is exactly how performance optimizations should be: unintrusive in terms of interface.

    It drives me nuts.

    Relax. Remember there's always somebody wrong on the internet.

    Just like any natural language it becomes weird if you over-use a particular feature. IMHO context sensitivity is nice, but best used sparingly. It should just DWIM, but when it's used too often I have to actually think about contexts, which defeats the whole purpose of contexts.

    And just like in natural languages opinions on how to best use it vary greatly, so I don't really expect to come to a consensus with you.

      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.
Re^6: No garbage collection for my-variables
by kyle (Abbot) on Sep 17, 2008 at 03:19 UTC

    Eschew obfuscation.

    There are parts of my natural language that I don't use for various reasons. I don't see why Perl should be any different.

        Obfuscation is actually beside my point. The point is we don't use every "feature" of our natural languages, and likewise I see nothing wrong with not using every feature of our programming languages.

        My children speak the same language I do, but they probably never will speak it the same way I do. There will be elements and idioms that I will use once in a while that they'll never use. Likewise, they will learn language constructs from their peers that I won't find all that expressive.

        You're correct that some programmers will go out of their way to avoid global variables. Some will go out of their way to have object orientation. And so on and so forth. That may be a result of their experience or a result of their education or even a result of some misunderstanding. In any case, it's a result of them being individuals.

        There are things I won't write because I had some bad experience in the past. I may not remember the details. I remember what got me into some trouble, and I still avoid it without remembering why. I don't see much problem with this as long as I can still "get the job done."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-25 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found