When comparing Go and Scala end of statement detection I found out that the rules for Scala are richer, namely:
A line ending is treated as a semicolon unless one of the following conditions is true:
- The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.
- The next line begins with a word that cannot start a statement.
- The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
Quoted from Scala - The rules of semicolon inference.
Rule #1 is how the Go works as well. Rule #3 too. The only difference is rule #2 – it involves single lookahead, since there is one token involved ("word").
What kind of performance penalty is involved: 1% slower, 5%, 10%?
I would love to see a comment (not the question) why Go designers left out that rule – if not for performance, it makes language more reliable, for example in method chaining:
x = some_object.select(...)
.sort(...)
.reverse(...)
.where(...)
.single()
If I am not mistaken for Go it is an error (you can solve it in two possible ways – taking entire statement in braces or expression in parentheses, but it is manual tweaking), Scala will take it as it should.