5 ms·
I agree with the general observation, but the need for ";" ? Quite a few languages (over a few generations) have been doing fine without the semicolon. Just to
by atleta 6y ago
I agree with the general observation, but the need for ";" ? Quite a few languages (over a few generations) have been doing fine without the semicolon. Just to mention two: python and haskell. (Yes, python has the semicolon but you'll only ever use it to put multiple statements on a single line.)
- yakshaving_jgt 6y ago> Yes, python has the semicolon but you'll only ever use it to put multiple statements on a single line. This is also true of Haskell btw.
- Cu3PO42 6y agoHaskell has the semicolon for the same reason!
- lelanthran 6y ago> I agree with the general observation, but the need for ";" ? Quite a few languages (over a few generations) have been doing fine without the semicolon. Just to mention two: python and haskell. (Yes, python has the semicolon but you'll only ever use it to put multiple statements on a single line.) But then it's inconsistent and has unnecessary complexity because now there's one (or more) exceptions to the rules to remember: when the ';' is needed. And of course if you get it wrong you'll only discover it at runtime. "Consistent applications of a general rule" is preferable to "An easier general rule but with exceptions to the rule".
- nightcracker 6y agoHave you ever used Python? If you did you really wouldn't be saying this. There isn't an exception. The semicolon is used to put multiple statements on a single line. That's it's only use, and that's the only time it's 'needed' - no exceptions.
- lelanthran 6y ago> Have you ever used Python? If you did you really wouldn't be saying this. There isn't an exception. For the ';', perhaps not. For the token that is used to terminate (or separate) statements? Yes, the ';' is an exception to the general rule of how to terminate statements. The semicolon also works on some sort of statements and not others, throwing errors only at runtime. It's easier to remember one rule than many.
- pedrovhb 6y agoHonestly, the rule is "don't use semicolons in Python". I don't think there's a single one in the large codebase I work with, and there's really no reason at all to use it other than maybe playing code golf. It's not a language in which you ever need be saving bytes on the source code. Just use a new line and indent. It's more readable and easier.
- c-cube 6y agoBut python has instead the "insert \ sometimes" rule, which isn't better.
- atleta 6y agoThere are no exceptions. You only need it if/when you want to put multiple statements on a single line. That's its sole purpose. And I'd also add that it's something that you almost never do. One practical use is writing single line scripts that you pass to the interpreter on the command line. E.g. `python -c 'print("first command"); print("second command")'` If you don't know about the `;` at all in python then you are 100% fine.
- labawi 6y agoWhen you use ; and possibly {, }, code statements / blocks are specified redundantly (indentation + separators), which can cause inconsistent interpretation of code by compiler / readers. I find it much, much easier to look at code and parse blocks via indentation, than the many ways and exceptions of writing ; and {, }, while an extra or missing ';' or {} easily remains unspotted and leads to silly CVEs.
- ufo 6y agoAnother inreresting example is Lua. It's a free form language without semicolons. It's not indentation sensitive.
- samatman 6y agoLua does have semicolons! It even has semicolon insertion, but because the language is carefully designed, this doesn't cause problems, and most users can go a lifetime without knowing about it. Our coding style requires semicolons for uninitialized variables, so you'll see local x; if flag then x = 12 else x = 24 end As a way of marking that the lack of initialization is deliberate. `local x = nil` is used only if x might remain nil.
- ufo 6y agoI don't like saying that it's semicolon insertion because it might give people the idea that the semicolons work similarly to Javascript. In Lua, inserting a semicolon is always optional and it's an stylistic matter (like in your example). It even allows putting multiple statements on the same line without a semicolon. -- Two assignment statements x = 10 y = 20