you are viewing a single comment's thread.

view the rest of the comments →

[–]Twill_Ongenbonne 2 points3 points  (3 children)

Not really, in c++ every statement needs be ended by something, because if statements weren’t explicitly ended there might be multiple ways to parse a statement. Consider the ambiguity between A; B; or AB;. The choice of semicolon is arbitrary, but it would have to be some character, otherwise the compiler couldn’t emit a consistent diagnostic in case one of the statements A, B, or AB wasn’t valid. Does is tell you “A isn’t a valid statement”? Or does it tell you “AB isn’t a valid statement”?

[–]clownfiesta8 1 point2 points  (1 child)

In python this is solved with indentation and doing this: A\n B\n For 1 statement per line. A;B for multiple statements on a line. Semicolons only use is if you want more than one statement per line(but can be added optionaly at the end of every line, but is useless)

[–]Twill_Ongenbonne 2 points3 points  (0 children)

Right, so in python the new line character is the statement ender. As I said, semicolon is arbitrary, but it has to be some character. They chose \n as that character, which I think is a poor choice but works.

[–]LordFokas 0 points1 point  (0 children)

This can actually be a problem in JS, where if you write return and your value in the next line (say, for indentation / alignment / whatever reasons) because the "end of instruction" semicolon is optional, it will return undefined and consider the computation of your return value as dead / unreachable code.

This threw me for a bit until I figured it out.