From: Robert Klemme Date: 2010-07-10T06:10:05+09:00 Subject: Re: what about allowing to specify, which end belongs to which start? On 09.07.2010 21:17, Ryan Davis wrote: > > On Jul 9, 2010, at 12:05 , Jan Lelis wrote: > >> I've recently come across a pretty common situation in Ruby: >> >> end end end >> >> After those parts, you often don't know, where exactly you have to >> continue. >> >> So what about allowing to specify, which end belongs to which >> start? I've thought about something like this: >> >> end|do end|if end|def >> >> or >> >> end~do end~if end~def >> >> or >> >> end:do end:if end:def Not to forget about end:case, end:class, end:module... >> If you specify it, and it does not match, the compiler throws an >> error. Of course, you can always omit it to have the normal The compiler as it is today will throw an error anyway. >> behaviour, but you are encouraged to often "document", which end >> belongs to which block (and you do yourself a favour in these >> nested situations). I think "encouraged" is the wrong word. Your extension would _force_ the user to use this idiom (which I personally find too verbose). Also, your solution does not help if you nest the same type of control flow statement. If you want to document nesting you can do that today already (and some people actually do it). But I agree with Ryan here: >> What do you think about it? > I think if you have so many ends that you need to extend the syntax > then you're doing something wrong to begin with (no pun). I try to > make all my methods short when I can, and I use judicious use of > extra returns to separate code into paragraphs to further help. I > think this type of syntax extension would further encourage large bad > codes. Plus, editors with auto indentation and code completion usually help. I personally have made it a habit to always write the opening and closing construct before I fill in the body. That way you can work pretty well even if your editor does not have fancy features. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/