Robert Klemme
12/12/2006 2:18:00 PM
On 12.12.2006 14:31, Dave Thomas wrote:
>
> On Dec 12, 2006, at 4:10 AM, Robert Klemme wrote:
>
>> I have low expectations with regard to the "else" clause but the book
>> clearly states that it is executed if there was no exception - that
>> includes the case where the block is left via a "return". Behavior
>> and description simply are not in sync, that's my point.
>
> Interesting: I'd honestly never have thought of that interpretation. I
> guess in my mind, the semantics of return take precedence over most
> other semantics, and I explicitly note the times where that's not the
> case. Thanks for pointing out an alternative.
Dave, you're welcome! I was probably in formal mode when reading that,
although I believe the situation here is a tad different from the
"while" loop case:
> Do you feel I should also document the other places when a return could
> be issued? For example, in the description of a while loop, I say
> "executes body zero or more times as long as boolean-expression is
> true." Should I add "or a return is executed or an exception is thrown"
> to this and similar descriptions?
Maybe just "... or the body of the loop is left via other control flow
statements". You could even add a footnote which enumerates them. :-)
> I kind of feel that this would clutter the descriptions, and that most
> readers would make the assumption that return and exceptions would break
> the flow. Is that an incorrect assumption?
I agree about cluttering and I think a change is not needed in this
cases - in other words, I believe it's not an incorrect assumption. :-)
I think the case with "else" clause after "rescue" clauses is a bit
different because control flow is not explicit like with loops. It is
immediately clear that "break", "return", "raise" and "throw" will
instantly leave the loop (is it?). However, with "rescue - else" we are
talking about less explicit control flow and so maybe a more explicit
description is helpful here.
As I said, it's probably a corner case and I have no idea how often this
"else" is actually used in applications. I for my part cannot remember
ever having used it - apart from the research for this thread.
It's a totally different question whether the behavior of the
interpreter should change so code in "else" clause is executed even for
a "return". There might be arguments in favor and against it. Maybe
Matz can shed some light about the reasoning why it is the way it is.
Kind regards
robert