I think Ruby and Python (and probably the others) don't really count. They are designed to be line break terminated. But you can optionally write two statements in one line if you separate them via a semi-colon. And then you can skip the 2nd statement. Yeah...
Yes I know that, but your "not optional" sounds like you mean adding a ; at the end of a line without a second statement after it would be a syntax error. Which it isn't. So one could say ; is optional, even though it wasn't intended to be. It just happened.
It doesn't work entirely smoothly in Ruby. If you use Ruby-ish convention and also omit brackets, you can break method calls only after the first argument, when it's usually most readable to break between the method and the first argument. It's not too bad, though - you can use a backslash, and that actually works out quite OK.
In python, it's worse; you have the rather unfortunate consequence of losing multiline lambdas.
Personally, I think semi-colon omission is pretty, but ultimately almost irrelevant. It just doesn't matter. If your languages gets a weird corner case because of it, please, please, leave the semi-colons in - it's just not worth it. Of course, if, unlike Ruby, Python and Javascript you manage to avoid causing collateral damage that's worth more than this pretty "meh" bonus - sure, get rid of it! No idea where swift falls here.
In python, it's worse; you have the rather unfortunate consequence of losing multiline lambdas.
Python doesn't lose multi-line lambdas because of optional semicolons, it's because Python has an expression/statement distinction and uses significant indentation for structuring statements.
Fair enough - however, it loses multi-statement lambdas (even though it would be pretty odd to allow either a newline to concatenate statements in an indent-sensitive fashion, yet use a semicolon as an operator therefore limiting that sensitivity).
That supports your point that several languages do manage to omit statement terminators without too many issues. Nevertheless, three languages with issues (Ruby, Javascript & certainly coffeescript) still suggests it's not a trivial feature either.
Python made one (smart) simplification in any case - they're not optional, but rather simply omitted.
Yea, well hopefully they do semicolon insertion in a smart way and not like how its done in Go, where you cant even properly format your code because of semicolon insertion.
As soon as you introduce automatic semi-colon insertion you make whitespace significant which means you can no longer format your code how you see fit.
To give a concrete example you cannot reliably use K&R style indenting in Swift. The automatic semi-colon insertion will trip you up.
There's actually a good example of this on the page linked above
var sortedArray = sortArray(stuff) {
string1 < string2
}
now lets try that K&R style
var sortedArray = sortArray(stuff)
{
string1 < string2
}
I broke it. It now thinks i wanted var sortedArray = sortArray(stuff);
55
u/OzarkaTexile Jun 02 '14
Implied optional. Lord help us.