[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Matz: can we have rescue/else/ensure available in all blocks?

Yukihiro Matsumoto

5/15/2008 11:17:00 PM

Hi,

In message "Re: Matz: can we have rescue/else/ensure available in all blocks?"
on Fri, 16 May 2008 07:02:47 +0900, coderrr <coderrr.contact@gmail.com> writes:

|This (contrived example):
|
|pages.each do |page|
| page.links.each do |link|
| process link
| rescue MalformedLinkError
| @bad_links << link
| end
|rescue MalformedPageError
| @bad_pages << page
|end

can be considered as

pages.each do |page|
begin
page.links.each do |link|
begin
process link
rescue MalformedLinkError
@bad_links << link
end
end
rescue MalformedPageError
@bad_pages << page
end
end

and

begin
pages.each do |page|
begin
page.links.each do |link|
process link
end
rescue MalformedLinkError
@bad_links << link
end
end
rescue MalformedPageError
@bad_pages << page
end

If it contains ensure, things are more complicated. Perhaps you would
expect

foo do
break
ensure
puts "foo"
end

would print "foo" even when foo does not give control to the block.


matz.

1 Answer

coderrr

5/16/2008 12:03:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Hey Matz,

Thanks a lot for the quick reply.

I agree it is possible that someone who doesn't know the syntax could
potentially misinterpret these things. I think though, that this should be
weighed against the benefit of adding it to the language. I assume it's
your judgment that the cost outweighs the benefit on this? I of course
think the opposite :)

I wonder what other developers think about how easily confused these would
be, and about how that weighs against the benefits?

The benefits are more concise syntax (which is the thing I love most about
ruby), removing 2 lines and an indentation for a lot of rescue statements

Also, I would be happy if only the ability to rescue were added to all
blocks but begin/end were required for else/ensure since they are less
commonly used.

- steve
http://coderrr.wor...