Date: Sun, 16 Jan 2022 09:01:24 -0600
On Sun, Jan 16, 2022 at 6:53 AM Ben Boeckel <ben.boeckel_at_[hidden]> wrote:
> On Sat, Jan 15, 2022 at 20:32:32 -0600, René Ferdinand Rivera Morell wrote:
> > On Wed, Jan 5, 2022 at 6:10 AM Ben Boeckel <ben.boeckel_at_[hidden]>
> wrote:
> >
> > > On Wed, Jan 05, 2022 at 08:10:08 +0000, Jonathan Wakely via SG15 wrote:
> > > > Maybe give it a default argument too. The difficulty then is whether
> it
> > > > should default to true or false, and whether true should mean
> conditional
> > > > or unconditional.
> > >
> > > Why are we limited to `bool`? Why not something like:
> > >
> > > ```
> > > enum class breakport_condition {
> > > always,
> > > when_debugged, // best effort
> > > never, // to allow for more complicated conditional logic leading
> up
> > > to the call
> > > };
> > > ```
> > >
> > > The discussion of the default is then down to just `always` or
> > > `when_debugged`, no?
> > >
> >
> > I don't see what "never" does? There's only one check to skip or not, so
> I
> > would think there's only two alternatives to choose from.
>
> It allows something like:
>
> ```
> const char* env = getenv("ENABLE_BREAKPOINTS");
> std::string dbg = env ? env : "";
> std::breakport_condition cond = std::breakport_condition::never;
> if (dbg == "yes")
> cond = std::breakport_condition::always;
> else if (dbg == "try")
> cond = std::breakport_condition::when_debugged;
> std::breakpoint(cond);
> ```
>
> instead of:
>
> ```
> const char* env = getenv("ENABLE_BREAKPOINTS");
> std::string dbg = env ? env : "";
> bool use_cond = false;
> bool cond = false;
> if (dbg == "yes") {
> use_cond = true;
> cond = true;
> } else if (dbg == "try") {
> use_cond = true;
> cond = false;
> }
> if (use_cond)
> std::breakpoint(cond);
> ```
>
> I think the former is *far* better than boolean soup.
>
I wasn't asking about enum vs. bool. I was asking about the "never" value.
Why is it needed when I can rewrite your example as:
===
const char* env = getenv("ENABLE_BREAKPOINTS");
const std::string dbg = env ? env : "";
if (dbg == "yes")
std::breakpoint(std::breakport_condition::always);
else if (dbg == "try")
std::breakpoint(std::breakport_condition::when_debugged);
===
Which is shorter and, IMO, more straightforward?
> On Sat, Jan 15, 2022 at 20:32:32 -0600, René Ferdinand Rivera Morell wrote:
> > On Wed, Jan 5, 2022 at 6:10 AM Ben Boeckel <ben.boeckel_at_[hidden]>
> wrote:
> >
> > > On Wed, Jan 05, 2022 at 08:10:08 +0000, Jonathan Wakely via SG15 wrote:
> > > > Maybe give it a default argument too. The difficulty then is whether
> it
> > > > should default to true or false, and whether true should mean
> conditional
> > > > or unconditional.
> > >
> > > Why are we limited to `bool`? Why not something like:
> > >
> > > ```
> > > enum class breakport_condition {
> > > always,
> > > when_debugged, // best effort
> > > never, // to allow for more complicated conditional logic leading
> up
> > > to the call
> > > };
> > > ```
> > >
> > > The discussion of the default is then down to just `always` or
> > > `when_debugged`, no?
> > >
> >
> > I don't see what "never" does? There's only one check to skip or not, so
> I
> > would think there's only two alternatives to choose from.
>
> It allows something like:
>
> ```
> const char* env = getenv("ENABLE_BREAKPOINTS");
> std::string dbg = env ? env : "";
> std::breakport_condition cond = std::breakport_condition::never;
> if (dbg == "yes")
> cond = std::breakport_condition::always;
> else if (dbg == "try")
> cond = std::breakport_condition::when_debugged;
> std::breakpoint(cond);
> ```
>
> instead of:
>
> ```
> const char* env = getenv("ENABLE_BREAKPOINTS");
> std::string dbg = env ? env : "";
> bool use_cond = false;
> bool cond = false;
> if (dbg == "yes") {
> use_cond = true;
> cond = true;
> } else if (dbg == "try") {
> use_cond = true;
> cond = false;
> }
> if (use_cond)
> std::breakpoint(cond);
> ```
>
> I think the former is *far* better than boolean soup.
>
I wasn't asking about enum vs. bool. I was asking about the "never" value.
Why is it needed when I can rewrite your example as:
===
const char* env = getenv("ENABLE_BREAKPOINTS");
const std::string dbg = env ? env : "";
if (dbg == "yes")
std::breakpoint(std::breakport_condition::always);
else if (dbg == "try")
std::breakpoint(std::breakport_condition::when_debugged);
===
Which is shorter and, IMO, more straightforward?
-- -- René Ferdinand Rivera Morell -- Don't Assume Anything -- No Supone Nada -- Robot Dreams - http://robot-dreams.net
Received on 2022-01-16 15:01:37