Re: Loosening the Loop

Peter Gummer <[email protected]> Tue, 29 Nov 2005 22:42:14 +1100
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
Roger Browne wrote:

>             from until done loop
>                ...
>                done := (operator = invalid_token)
>                if not done then
>                    ...

That sort of thing is fairly common. I find it very, very annoying  
whenever I have to check the 'done' condition twice and then indent  
an extra level. It hurts legibility. When an algorithm is already a  
bit complex, such as this example, then any small simplification  
makes it easier to read and to verify.

It's worth noting that your example could be simplified by extracting  
the 'inspect' statement out to a separate routine. This might make  
the loop easier to read, but there would still remain a one-line call  
to the extracted routine. So the problem would remain. I think the  
only way around this would be to make the extracted routine a  
function with a side-effect; but of course we wouldn't want that,  
would we ;-)

I'd love to know why Bertrand Meyer objected to your suggestion ten  
years ago. You've mentioned that he has changed his mind on a few  
issues over the years. Maybe he would be prepared to reconsider this  
too.

- Peter Gummer