-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
leads questionA question for the leads teamA question for the leads team
Description
The if/else proposal mentions two alternatives at the end: "No parentheses" and "Require braces". The conclusion was:
The benefits of this are debatable, and it should be examined by an advocate in a focused proposal. For now, we should match C++'s decision.
I would like to discuss the topic a bit more.
- In C++, braces after a
if
are optional. In practice, many style guides require the use of braces, e.g. https://google.github.io/styleguide/cppguide.html#Conditionals - Giving the choice of having braces doesn't seem useful, if style guides are likely to discourage it. It also conflicts with the One Way Principle.
- Making braces mandatory allows us to remove the parenthesis around the expression:
if x {
do_parse = false;
}
- Parenthesis are already used in lots of different places in the grammar: function calls, precedence, generics... Removing parenthesis here can reduce the overloading.
- This idea has been successfully used in other languages (e.g. Go), and probably won't disrupt people familiar with C++ (if they put the parenthesis after a if, they would just be useless).
- Removing the parenthesis would be more consistent with the Conditional expressions syntax (
if cond then x else y
).
For consistency, the syntax of while
and for
would need to be updated as well:
while x { ... }
for var i : mylist { ... }
kammce, MaliaLabor, Smil3yFace, galchinsky, 21pdavis and 4 more
Metadata
Metadata
Assignees
Labels
leads questionA question for the leads teamA question for the leads team