Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: RFC: Simulating Ruby's "yield" and "blocks" in Perl

by Jenda (Abbot)
on Apr 23, 2013 at 01:03 UTC ( #1030013=note: print w/ replies, xml ) Need Help??


in reply to RFC: Simulating Ruby's "yield" and "blocks" in Perl

For gawds sake why would I want to do anything that silly, replacing something readable with the use of an ill-designed and ill-named nonsense? Yieiaild? There's nothing in the dictionary that would match the way this keyword is used in Ruby. Yeah, yield as a keyword related to coroutines, fine. You yield the execution and let someone outside the subroutine decide when to continue, but that's not what it means in Ruby!

sub test (&){ my $print = shift; say "You are in the method"; $print->(1); say "You are again back to the method"; $print->(2); } test { say "You are in the block $_[0]" };

is not only more readable, but also more extensible! You are not restricted to a single "callback" and if you need to pass the subroutine reference/closure/block (I know the differences, thank you very much) somewhere else you can! Try that in Ruby!

BTW, does the |a,b| finally declare new variables in Ruby or does it still reuse the a and b if they happen to be defined? Yeah, I know, a method in Ruby should not take more than four lines ... it doesn't matter you end up having hundreds of them.

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re: RFC: Simulating Ruby's "yield" and "blocks" in Perl
Select or Download Code
Re^2: RFC: Simulating Ruby's "yield" and "blocks" in Perl
by LanX (Canon) on Apr 23, 2013 at 01:40 UTC
    You seem to be somehow ... tensed ...

    ... everything alright with you?

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Mostly just bad memories. I was forced to work with Ruby a few years ago. The language is ugly.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-12-29 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls