4 ms·
when did it become so trendy to hate semicolons?
by trotsky 14y ago
when did it become so trendy to hate semicolons?
- seanmcdirmid 14y agoA small but very vocal sub community of programmers hates semicolons. Really, semicolons are nice for readability and nice for your tools, as they make statement termination explicit. I was on the losing side (a semicolon lover) of this debate when it came to scala.
- icebraining 14y agoI think this is mostly bikeshedding, but I can't agree with your statement. The claim is not that we shouldn't have explicit statement terminating characters. It's that we already have one - new lines - and that mandating semicolons is both redundant and bug prone. Personally, and while it doesn't really affect my choice of languages, I think you should be able to use one or the other, but not two consecutively. In any case, excuse me for posting this, and I promise I won't discuss it here any more.
- AndrewDucker 14y agoI frequently split long statements over multiple lines for readability purposes. Having an explicit statement terminator makes this possible.
- anonymoushn 14y agoYou can do this without an explicit statement terminator. In Scala, you can write something like this and just have it work. foo.bar(arg, objectToComputeArg2.computeArg(innerArg1, innerArg2, innerArg3), arg3) You can do the same in Python or in Lua. Lua will yell at you when it's actually ambiguous, as in function_returning_a_function(arg)(arg_to_returned_function) (it_is_not_clear_whether_this_is_a_call_to_the_value_returned_by_the_previous_line()) You can disambiguate this with parentheses or using a semicolon, though. There's never actually a need to use a semicolon.
- jerf 14y agoHaving an explicit terminator makes it maximally flexible, but certainly not "possible". Python does it just fine, but the rules, while mostly sensible, do have a couple of corner cases that can catch you. Javascript does it somewhat less fine, with quite a few more corner cases, including a couple that definitely routinely hit people. But in both cases, it can be done. Nor are those the only two examples.
- mbell 14y agoI do this all the time in Groovy and don't use semicolons...
- vorg 14y ago> I do this all the time in Groovy and don't use semicolons Groovy's semicolon-less mode has lots of syntax restrictions. E.g.this doesn't compile... println true ? "yes" : "no"
- mbell 14y ago> Groovy's semicolon-less mode has lots of syntax restrictions. E.g.this doesn't compile... I would't say 'lots'. It pretty much boils down to one thing: 'leave the operator on the previous line' println true ? "yes" : "no" For example is just fine.
- vorg 14y agoThis compiles and runs OK in Java... class Hello{ public static void main(String[] args){ System.out.println( true ? "yes" : "no" ); } } In order to work without semicolons, Groovy's grammar must restrict some things that work in Java. Semicolon-less mode in Groovy has a price.
- JoeAltmaier 14y agoOk, I've always wondered about that '?' operator. What's the point? It was said (at the time) that C-like syntax meant a program was a series of expression, not statements. So something like (void)1; is valid syntax. Even compound expressions are valid: a=5, b=6; Where I feel abandoned (betrayed?) is this: why then aren't compound statements also expressions? E.g. { int x=Foo(50); Bar(x); } The value returned could just be the value of the final executed expression (Bar yields a value). No need for 'return' at all. And no need for '?'. int x = { if (i > j) 5; else 6; }
- 14y ago
- rdtsc 14y agoI program in Python (no semicolons) and I also frequently split long statements over multiple lines. One doesn't need an explicit statement terminator to do it. You can do it inside parentheses for ex.
- seanmcdirmid 14y agoI have first hand experience that semicolons are good for tools. I've also helped people debug their Scala compilations by having them add semicolons on various lines to make the error messages more comprehensible. If we didn't have multi-line statements, new lines would work great as statement terminators.
- agumonkey 14y agoIsn't this part of a trend to reduce the presence of statements (enforcing order-based reasoning) ? With javascript ubiquity and mainstream presence of lexical closure people converge toward functional, encoding of patterns, even sequences.
- seanmcdirmid 14y agoI think you are right but I disagree with the trend. Debugging a wide horizontal expression is much harder than debugging a tall vertical sequence of statements.
- agumonkey 14y ago'for now'. Current debuggers aren't built to handle this point of view. I agree it's quite frustrating, but I'd bet it will be fixed soon.
- seanmcdirmid 14y agoI work in this area and I'm not so sure the fix will be easy. There seems to be a real "cognitive" cost to abstractions such as deep chains of combinators, which spills over into debugging. How the heck are you supposed to debug something when the control flow is abstracted N-layers deep? You really can't, which means you have to resort to something like data-flow debugging.
- goldfeld 14y agoAround the same time vi won over emacs.
- rdtsc 14y agosince many realized they are not needed...? why do you need semicolons?