Language: Optional or no parentheses in control flow statement, eg: if true { }

Created on 14 May 2019  路  1Comment  路  Source: dart-lang/language

Hi dartlang team,
Is there any chance in the future, we can code like this in dart:

if true {
  print("It's awesome")
}

just like in Python, Go, Swift.

>All comments

I think this is very unlikely. I like the syntax in those languages, but this is a corner of Dart's syntax that is very entrenched at this point. Removing those parentheses could possibly cause ambiguity with other parts of the grammar. There's some stuff that after 1.0 you're pretty much stuck with, for better or worse.

In practice, I somewhat prefer Dart's syntax because it makes single-line if statements look cleaner:

if (min > max) throw "Bad range";

Also, the familiarity to users coming from C++, Java, C#, and JavaScript is a significant value.

Was this page helpful?
0 / 5 - 0 ratings