Boost logo

Boost :

Subject: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakablelibrary?
From: Pierre Morcello (pmorcell-cppfrance_at_[hidden])
Date: 2009-09-06 19:34:04


vicente.botet wrote
>>>>"The isea to rerplace a goto with a loop and a break is interesting, but I agree with Sebastian, why your macro is more readable than"

For 1 'breakable struct', there is yes, not much use. But when you begin to embbed one within another, it can be nicer to read.

>>>>"I'll not include a header library just for this."

Thanks for your point of view. Someone else made this remarks too. My answer is : I consider that not everyone is aware of this useful struct. This is the same for a boost::non-copyable. You can easily write the private copy constructor & so on yourself without boost. But the fact that it exists, will give a more broader spread of this simple idea. And good if people wants to write their own. But as you can see, even on this forum, some people never thought of this use of a simple breakable part.

>>>>Sebastian Redl wrote :
"You say that your macro makes the code more readable, but what probably would make it even more readable would be restructuring it."

You can have a look at the example of pseudo code of a reading of a xml I posted to choose which version you prefer.

>>> David Bergman wrote:
"I would probably listen more to a very experienced developer than a newbie.."
Well the fact is I try (as more as I can) to listen always with maximum concentration to whoever speaks to me.

>>> On a more serious subject ;-), David Bergman wrote:
The reason that I mentioned all this at all was that you talked about making the code more readable by using your 'breakable construct', where I here argue that if readability is a concern, one should be wary of using breaks at all.

Thanks for this point of view. Let me explain mine : you are telling basically SESE(single entry single out) is good for readability, and the other things are not that good. Well (long ago), GOTO was a pain to maintain in less recent languages. Programmers made a lot of efforts to get rid of it, and 'won' through the wide spread of SESE as a rule of thumb.
Now, goto are never to be seen in C++ (sincerely I have never seen one in C++), so I can say we are 'freed' of this kind of problems. So it is ok to do break.

I worked with pure SESE during 7 years, (image processing, GUI, reflection systems,...). Then I tried to change my habits by using 'breaks' in loops. Things were better most of the time. That is how I eventually tried the 'brekable struct'. Since I use it, I find things are organized even nicer in my code.

Best regards,

Pierre

--- En date de : Dim 6.9.09, vicente.botet <vicente.botet_at_[hidden]> a écrit :

De: vicente.botet <vicente.botet_at_[hidden]>
Objet: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakablelibrary?
À: boost_at_[hidden]
Date: Dimanche 6 Septembre 2009, 12h48

Hi,
----- Original Message -----
From: "Pierre Morcello" <pmorcell-cppfrance_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, September 06, 2009 7:58 PM
Subject: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakablelibrary?

Hi, there is no difference.

Indeed, the macro as I use it right now is even less optimised than a GOTO or a do...while(false) : it's currently just a simple 'for' loop in a macro...

The aim is to make code more readable. A goto is a pain to manage when you use a lot this 'breakable' structure. The fact that it is easy to use and readable makes it easier to use a lot. In the end, I happen myself to use it lot more than I thougth I would at first. That is the main reason why I am proposing it here.

>>>Both are probably shorter to write.
Yes, although someone using such library may redefine the macro as he wishes :
e.g. #define Breakable BOOST_BREAKABLE
I am just conforming to BOOST coding style.

Pierre

--- En date de : Dim 6.9.09, Sebastian Redl <sebastian.redl_at_[hidden]> a écrit :

De: Sebastian Redl <sebastian.redl_at_[hidden]>
Objet: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakable library?
À: boost_at_[hidden]
Date: Dimanche 6 Septembre 2009, 9h10

Pierre Morcello wrote:
> Hello,
>
> I propose a set of macros that allow to break anywhere. Example of use of the main macro :
>
> // do something...
> BOOST_BREAKABLE
> {
> if (test1)
> {
> break;
> }
> if (test2)
>
> {
>
> break;
>
> }
>
>
> std::cout<<"this is never reached if test1==true or test2==true. "<<std::endl;
> // do something...
> }
> // here the program continues ...
>
> Is there any interest in such a library?
>
What's the difference between this and a goto? Or a do ... while(false);
loop? Both are probably shorter to write.

Sebastian
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

The isea to rerplace a goto with a loop and a break is interesting, but I agree with Sebastian, why your macro is more readable than

do {
    if (test1)
    {
        break;
    }
    if (test2)
    {
        break;
    }
    std::cout<<"this is never reached if test1==true or test2==true. "<<std::endl;
    // do something...
} while(false);

or

for (bool executed=false;!executed;executed=true) {
    if (test1)
    {
        break;
    }
    if (test2)
    {
        break;
    }
    std::cout<<"this is never reached if test1==true or test2==true. "<<std::endl;
    // do something...
}

I'll not include a header library just for this.

Best,
Vicente

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk