Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Perl to Ruby translator?

by Aristotle (Chancellor)
on Oct 10, 2003 at 18:43 UTC ( [id://298368]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Perl to Ruby translator?
in thread Perl to Ruby translator?

This may sound arrogant, but - to what level of programmers? I can count on the fingers of one hand (with several to spare) the number of times I got myself in a bind with closures. As the old adage goes, real programmers can write FORTRAN in every language - I doubt anyone who makes a mess with Perl would write clean and sophisticated code if just given another language.

I don't want to close the post on that note; I understand your concern and know just taking the indoctrinated stance on this doesn't make the problems in practice go away. But in my experience trading expressiveness for simplicity does not pay off in the long run. ("Simplicity" is not quite the right word either.)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^3: Perl to Ruby translator?
by perrin (Chancellor) on Oct 10, 2003 at 19:00 UTC
    People often don't realize that this is a closure:

    my $q = CGI->new() sub foo { my $thing = $q->param('thing'); }
    Then they try to use it in a persistent environment like mod_perl or FastCGI and they get screwed. I see this happen all the time.
      For at least my own education, if no one elses, how exactly is that a closure and why are people getting screwed doing it? It seems fairly simple to me..
        It's a closure because the sub foo refers to $q, which is a lexical variable delcared in the enclosing scope. Now, for the rest of the life of this Perl interpreter, the $q inside of the foo subroutine will always have the same value it did the first time this code was run, no matter what you do in the main part of this program. That means you will get crazy results where CGI.pm appears to be caching data from previous requests.

        It's a closure because it contains a reference to a lexical variable ($q) from a parent scope. It could cause problems if later you reassigned $q and thought it would change inside the sub, or thought it go away after the scope of $q ended.

        kelan


        Perl6 Grammar Student

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found