Boost logo

Boost :

Subject: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakable library?
From: Pierre Morcello (pmorcell-cppfrance_at_[hidden])
Date: 2009-09-06 17:09:52


>>>>What is a "break-scope problem" to you? I think you might use the wrong "analysis pattern" here...

I was reusing the same kind of words than the previous comment of Stefan Strasser, to answer clearly to his remarks. Sorry if it made things less clear: He wrote
"if you need a construct that forms a scope, accomplishes a tasks and then
exists the scope from anywhere in between, that's a function.". He was presenting things like a problem and its solution.

I have never heard of 'analysis pattern', only 'design patterns' and 'idioms'. I will look at this.

Anyway just let compare 2 sample codes:

Of course people can already write :
if(!filestream.bad())
{
   if(!filestream.good())
  {
    if(xmlLoadFrom(filestream))
   {
       // and so on, to test if the xml is valid, etc...
   }else{
      log("the file is no xml document.");      
    }
  }else{
    log("error inside the file (eof)");
   }
}else{
  log("error at opening file");
}

and :

Breakable
{
  if(!filestream.bad())
  {
      log("error at opening file");
      break;
  }

  if(!filestream.good())
  {
     log("error inside the file (eof)");
     break;
  }

  if(!xmlLoadFrom(filestream))
  {
     log("the file is no xml document.");
     break;   
  }
 
  // and so on, to test if the xml is valid, etc...
}

Have a deep breath, compare, and then tell me which is more readable.
Which is the easier to maintain?
If another test is to be added, which version will be the simpliest to modify?

For these 3 reasons, I prefer the second one.

If you think this usage might lead to problems, could you explain which ones ?

Best regards,

Pierre

PS: if you know a good source about "analysis pattern", don't hesitate to tell me. Right now, I will check the wikipedia page.

--- En date de : Dim 6.9.09, David Bergman <David.Bergman_at_[hidden]> a écrit :

De: David Bergman <David.Bergman_at_[hidden]>
Objet: Re: [boost] [Boost.Breakable] Any interest in a Boost Breakable library?
À: boost_at_[hidden]
Date: Dimanche 6 Septembre 2009, 13h08

On Sep 6, 2009, at 4:05 PM, Pierre Morcello wrote:

>>>>>> if you need a construct that forms a scope, accomplishes a tasks and then
> exists the scope from anywhere in between, that's a function.
>
> Yes, I remember thinking like this at the beginning. But declaring a function each times sometimes makes the code less readable. It's like declaring a functor for iterating over all objects of a collection : you can do it but BOOST_FOREACH is just much more readable. What is more you need to give a name to your function. It's just more complicated than just writing the name of the macro.
>
> Creating a function when you only want to solve a break-scope problem

What is a "break-scope problem" to you? I think you might use the wrong "analysis pattern" here...

> is doing too much IMHO. It's using a specific aspect of the language that allows to break anywhere, not a tool that is meant to do it

/David
_______________________________________________
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