Date: Sat, 20 Apr 2024 19:34:15 +0000
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.
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.
________________________________
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
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.
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.
________________________________
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
Received on 2024-04-20 19:34:21