[swift-evolution] Proposal: Make braces optional much like semicolons.

Amir Michail a.michail at me.com
Sun Dec 20 09:17:24 CST 2015


// braces are optional here but you could still put them in if you want to
for i in 0..<10
    for j in 0..<5
        if i % 2 == 0
            print(i+j)
        print(i*j)

// braces are necessary because “print" is on the same line as ”if"
for i in 0..<10
    for j in 0..<5
        if i % 2 == 0 { print(i+j) }
        print(i*j)

// braces are necessary with incorrect/unconventional indentation
    for i in 0..<10 {
for j in 0..<5 {
if i % 2 == 0 {
print(i+j)
}
print(i*j)
}
}

As for the space vs tab issue, my preference would be to allow only spaces to make braces optional. An alternative would be to use the python 3 indentation rules with respect to spaces and tabs.


More information about the swift-evolution mailing list