I agree with your conclusion, but possibly not your reasoning.

C++ should try to be more beginner friendly.  We should be willing to pay _some_ price ("work for ourselves") for that. The question is how much.
And note that the work can also help C++ "expert(s)".

But fundamentally, C (not just C++) is a language built by combining small expressions.  a = b is an expression, that does the same thing, regardless of whether it is in an if or not.  Making a special-case for "inside an if" is more complicated, not simpler.
Special-casing is the antithesis of language design.  Special-casing is NOT beginner friendly.  It appears so on the surface, but just leads to too many cases to memorize, so long term (more importantly - medium term) it is unfriendly.

Once the beginner learns this fundamental rule of expressions and rule of "combine simple concepts/blocks into bigger blocks", much of the language becomes _easier_.

So it is not a question of beginner vs expert it is beginner vs just-past-beginner.  Simplicity of "fundamental blocks combined together" helps the just-past-beginner.  The expert can do either simplicity or tons of special cases, they don't care, they are experts.

On Thu, Oct 24, 2019 at 3:40 PM Nicholl, Ryan via Std-Proposals <std-proposals@lists.isocpp.org> wrote:

I have to strongly oppose the suggested change. It breaks old working code just to make it harder to make beginner mistakes. C++ is expert oriented, we shouldn’t be making work for ourselves just to make the language slightly cushier.


From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> On Behalf Of Brian Bi via Std-Proposals
Sent: Wednesday, October 23, 2019 12:44 PM
To: std-proposals@lists.isocpp.org
Cc: Brian Bi <bbi5291@gmail.com>
Subject: Re: [std-proposals] Prevent Assignments from contextually converting to bool


*External Message* - Use caution before opening links or attachments


On Wed, Oct 23, 2019 at 11:35 AM connor horman via Std-Proposals <std-proposals@lists.isocpp.org> wrote:

This is my proposed to solution to one of the worst logic errors in any number of languages, being:





The proposal is to tweak the wording of contextual conversions to bool, prohibiting unparenthesised assignments from being eligible for contextual conversion. Code that intends to do this can simply put parenthesis around the assignment or use an init-statement, and code that does this without intention (i.e. intends the comparison) would be elevated from a logic error (the worst kind honestly) to a compile-time error.

Std-Proposals mailing list


You can achieve this effect using compiler warnings. For example, with GCC and Clang, you can use the flag -Werror=parentheses to treat this as an error.


I do not think we should add more rules to the language that discriminate among expressions on the basis of properties other than their type and value category.



Brian Bi

Std-Proposals mailing list

Be seeing you,