4 ms·
Right, that's exactly what I'm saying. They're NOT optional in any of those languages. Some of them (Kotlin and Go) don't have them, but there is no argument.
by nobleach 4y ago
Right, that's exactly what I'm saying. They're NOT optional in any of those languages. Some of them (Kotlin and Go) don't have them, but there is no argument.
- nequo 4y agoOh, I misunderstood. I don't know Go very well but they do seem optional there: $ cat with_semicolons.go $ cat without_semicolons.go package main package main import "fmt" import "fmt" func main() { func main() { var x = 3; var x = 3 x += 1; x += 1 fmt.Printf("%d\n", x); fmt.Printf("%d\n", x) } } $ go run with_semicolons.go $ go run without_semicolons.go 4 4 $ $
- Beltalowda 4y agoGo requires every line to end in semi-colons if you look at the EBNF in the specification, but the compiler will insert them for you. It's kind of a subtle detail, but it shows up in some places, for example the following being a compile error: if true { } else { } Because the semicolon is inserted when the last character on a line is "one of the operators and punctuation ++, --, ), ], or }" (among other cases, see https://go.dev/ref/spec#Semicolons https://go.dev/ref/spec#Semicolons). So you need to use the } else { style. In practice, you can just leave of the semicolons at the end of lines (gofmt will remove them) and it's as if semicolons are not required, but if you want to get all technical about it then they are required.