C++ Logo

std-proposals

Advanced search

Re: [std-proposals] if !(condition)

From: Andrew Tomazos <andrewtomazos_at_[hidden]>
Date: Sun, 21 Apr 2024 07:49:13 +1000
Jens,

16.5% of if statements are like `if (!expr)`

You're welcome.
  -Andrew.

PS (`if(`=7495313 / `if(!`=45254716) in ACTCD19

PSS Yes, I checked `if(!` was dominated by `if(!expr)`

On Sun, Apr 21, 2024 at 7:05 AM Jens Maurer via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
>
> On 20/04/2024 21.34, Yexuan Xiao wrote:
> > Thank you for pointing out the error in my proposal; I’ll try to correct
> it in a later version.
> >
> > The data from LLVM or GCC shows code that directly benefits from this.
> Additionally, I searched all the Ruby code in Rails (a Ruby web framework
> with many users), where ‘unless’ appeared 1808 times, while ‘if’ appeared
> 10157 times. This data demonstrates the potential of the ‘if not’ pattern.
>
> You're answering a question I didn't ask.
>
> I asked: How many "if" statements are there in LLVM in total?
>
> By my crude count, for all of "llvm-project":
>
> $ find . -name *.h -o -name *.cpp | xargs grep -w '[^#]if' | wc -l
> 498710
>
> That's far less than 1% of "if" statements that would benefit.
> I'm not convinced by those numbers.
>
> > C++23 accepted ‘if !consteval’ instead of ‘if consteval(false)’, and
> the previous proposal P1181 has revealed other advantages, so I believe
> adding ‘if !constexpr’ or simply ‘if !’ is not a wart.
>
> You're welcome to disagree with me.
>
> The ISO standardization process is a consensus-driven process,
> and I'm herewith advising you, as early in the process as possible,
> of my opinion regarding your proposal.
>
> Absent further convincing rationale, I believe your proposal does
> not provide sufficient benefits in return for the added complexity,
> and I'll vote strongly against your proposal at any opportunity
> where I have a chance to do so.
>
> I hope that clarifies my position.
>
> Jens
>
>
>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > *From:* Jens Maurer <jens.maurer_at_[hidden]>
> > *Sent:* Sunday, April 21, 2024 3:01
> > *To:* std-proposals_at_[hidden] <std-proposals_at_[hidden]>
> > *Cc:* Yexuan Xiao <bizwen_at_[hidden]>
> > *Subject:* Re: [std-proposals] if !(condition)
> >
> >
> >
> > On 20/04/2024 18.09, Yexuan Xiao via Std-Proposals wrote:
> >> I've wrote a proposal that suggests allowing the omission of the
> outermost parentheses to simplify the conditions in if statements:
> >>
> https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstorage.nykz.org%2Fproposals%2Fif-not%2F&data=05%7C02%7C%7Cb53d7d71b9eb4c67433f08dc616c49c7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638492364927500272%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=Njw2Jwu1tWH8azBLMKGy6%2F2GPKqCr2uYCFBoxqsdvDc%3D&reserved=0
> <https://storage.nykz.org/proposals/if-not/>
> >>
> >> Please share your comments.
> >
> > A "condition" might be a declaration. The "equivalent" syntax
> > "!(condition)" is not valid C++ if the "condition" is a declaration.
> >
> > Thus, your proposal seems incomplete.
> >
> > You quote 1500 simplification opportunities in LLVM and 2300 ones
> > in GCC. How many "if" statements are there in total, in each of
> > those codebases?
> >
> > Beyond that, I'm strongly opposed: this delivers no benefit at all.
> > Being able to omit nested parentheses in the condition in some
> > cases (but not others, if the negation isn't at the top level)
> > is insufficient motivation for another wart in the language,
> > in my view.
> >
> > Someone hiding expression syntax in a macro is just misguided;
> > I have no sympathy whatsoever.
> >
> > Jens
> >
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-04-20 21:49:25