Skip to content

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Oct 23, 2025

Adjusted all code example according to ES.23: Prefer the {}-initializer syntax.

Note that this rule does allow using = with auto, but it appears more consistent to just use the {} syntax for auto as well.


Honestly it's also OK for me to use = with auto, but then I would still like to know if the code examples are really meant to support using = with auto. Otherwise I think it's clearer to just use the {} syntax in the code examples (as proposed by this pull request).

Adjusted all code example according to "ES.23: Prefer the {}-initializer syntax".

Note that this rule does _allow_ using `=` with `auto`, but it appears more consistent to just use the `{}` syntax for `auto` as well.
@N-Dekker N-Dekker force-pushed the Replace-=-with-brace-initialization branch from 1f4b81a to b21864c Compare October 23, 2025 15:36
@jwakely
Copy link
Contributor

jwakely commented Oct 23, 2025

Personally I would prefer to rewrite (or remove) ES.23

The rules for {} initialization are simpler, more general, less ambiguous,

Those are all debatable.

and safer than for other forms of initialization.

Probably true.

Use = only when you are sure that there can be no narrowing conversions.

Or when you are writing generic templates and don't want to gratuitously reject code that actually works fine.

Almost every time we've used {} in the standard library spec, it's been a mistake and we've changed it.

@N-Dekker
Copy link
Contributor Author

Thank you for your reply, @jwakely !

Note that this pull request still allows users to use = with auto declared variables. This PR only adjusts the examples, not the rules. And as far as I know, for auto declared variables, there is no semantic difference between brace-initialization and = initialization. So you might consider this a cosmetic PR. But it seems like using brace-initialization for auto variables (this PR) is in line with the current wording of ES.23: Prefer the {}-initializer syntax.

On the other hand, I would be very interested to see an update of ES.23 that would possibly make things clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants