Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing "<condition> is true|false" #4713

Open
tkoeppe opened this issue Jun 21, 2021 · 9 comments
Open

Missing "<condition> is true|false" #4713

tkoeppe opened this issue Jun 21, 2021 · 9 comments
Labels
big An issue causing a large set of changes, scattered across most of the text.

Comments

@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 21, 2021

In [utilities]. we say things like "get() == nullptr." a lot instead of "get() == nullptr is true." in many places.

We should decide whether we want to demand a specific style, and if so, document that style and fix the existing text.

@jensmaurer jensmaurer added big An issue causing a large set of changes, scattered across most of the text. decision-required A decision of the editorial group (or the Project Editor) is required. labels Jul 2, 2021
@ViralTaco
Copy link

TL;DR: In my opinion, adding "is true" doesn't clarify the subtext.

(expr == nullptr) means that evaluating expr results in a nullptr value, i.e.: it doesn't represent of valid pointer, as far as I understand (near).
It's strictly equivalent to not expr which, in-turn, is equivalent to not (expr != nullptr)
"not not equal is, by definition, equal"

@jensmaurer
Copy link
Member

Recently, we have preferred "expression is true". The argument is that expression alone does not form a grammatical English sentence. If we say "Preconditions: get() != nullptr", that's probably valid C++, but not English. Further, the idea is that the "is" asks for evaluation of the expression, not just its well-formedness or similar aberrations.

@ViralTaco
Copy link

"expression is true" is, arguably, no closer from forming a "grammatical English sentence".
I read == as "is equal to" and != as "is not equal to".
'A is equal to B' is 'true'. That's not better for me. I understand what you're saying. I just disagree.

@jwakely
Copy link
Member

jwakely commented Aug 12, 2021

I read == as "is equal to"

But when it appears in code, it's an expression that may or may not be true. Otherwise, the third operand of x == y ? op2 : op3 would never be evaluated, and if (x == y) {} else {} would never take the else branch. C++ is not mathematics, and the == operator is a predicate, not an assertion.

The core of the issue is that [structure.requirements] p4 says "Requirements are stated in terms of well-defined expressions that define valid terms of the types that meet the requirements." So if the spec just says "Preconditions: get() != nullptr." then all we're requiring is for the expression to compile and have a well-defined value (so get() doesn't return an indeterminate value or invalid pointer). There would be no requirement for it to have a particular result (true or false). It's not about how you read the wording; the standard defines its terminology and conventions, and so it needs to follow them.

We should decide whether we want to demand a specific style, and if so, document that style and fix the existing text.

We could consider blanket wording that says when we use a conditional-expression in a Constraints:, Mandates:, or Preconditions: element, that we mean it has to be true. If we say that's what it means, then that's what it means. The problem is that today we don't say it, so we need the explicit "is true" and "is false" wording everywhere.

If we don't add something saying that, then I think we do need to add the missing "is true" cases in [utilities] and elsewhere.

@ViralTaco
Copy link

Oh… 🤔 Ok, I get it now. (Took time)
However, in “is true” wouldn't you agree that “is” feel like it refers to an identity, and not a value? 🧐
Does "evaluate" fit in there?

So if the spec just says "Preconditions: get() != nullptr." then all we're requiring is for the expression to compile and have a well-defined value

Ok, I underestimated the gravity of the situation.
How about “Evaluation of the expression get() != nullptr produces the value true”,
or maybe “get() != nullptr shall be true”.

I'll agree with “is” if everyone believes “is” is fine. What is is is urgent 😎

@CaseyCarter
Copy link
Contributor

The core of the issue is that [structure.requirements] p4 says "Requirements are stated in terms of well-defined expressions that define valid terms of the types that meet the requirements." So if the spec just says "Preconditions: get() != nullptr." then all we're requiring is for the expression to compile and have a well-defined value (so get() doesn't return an indeterminate value or invalid pointer). There would be no requirement for it to have a particular result (true or false). It's not about how you read the wording; the standard defines its terminology and conventions, and so it needs to follow them.

[structure.specifications]/3.3 says that "Preconditions" specify "the conditions that the function assumes to hold whenever it is called; violation of any preconditions results in undefined behavior." If get() != nullptr is a "condition that must hold", I don't think there's much danger of someone misreading that to imply anything other than that get() != nullptr must evaluate to true.

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Aug 12, 2021

It may be that expressions involving == or != would be clear enough, but we have other kinds of expressions, too, where embedding them in an English phrase improves clarity. A uniform style of always writing a complete English phrase is thus simple and effective, and the "is true" wording is short enough to not get in the way. I don't see a strong reason to change this, or any serious fault with it.

Yes, we could have blanket wording, but blanket wording comes at a price, too, and I'm not convinced it would improve matters here.

@jensmaurer
Copy link
Member

How about “Evaluation of the expression get() != nullptr produces the value true”,

That's lengthy.

or maybe “get() != nullptr shall be true”.

We want to avoid "shall" because it makes for worse overall reading pleasure.

So, "shall be" -> "is", and we are at the status quo.

@tkoeppe
Copy link
Contributor Author

tkoeppe commented Sep 24, 2021

Editorial meeting consensus: We would like to adopt the "is true" style generally. We will add it to the wiki and update the non-conforming places.

@tkoeppe tkoeppe removed the decision-required A decision of the editorial group (or the Project Editor) is required. label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big An issue causing a large set of changes, scattered across most of the text.
Projects
None yet
Development

No branches or pull requests

5 participants