2 ms·
No, as python and other languages amply demonstrate, the semicolon is for the compiler, not the developer. If the compiler is sophisticated enough to figure out
by glitchc 2y ago
No, as python and other languages amply demonstrate, the semicolon is for the compiler, not the developer. If the compiler is sophisticated enough to figure out that a semicolon is needed, it has become optional. That's the OP's point.
- taormina 2y agoBut the language spec for Python is what allows for this, not the compiler. \n is just the magic character now except now we also need a \ to make multiline expressions. It’s all trade offs, compilers are not magic
- scotty79 2y agoScala then. Semicolons are optional but you still can have them if you need them
- lblume 2y agoThe obvious example would have been JavaScript, but nobody wants to say something positive about JavaScript...
- scotty79 2y agoJavaScript has some specific and unique issues. Some silly choices (like auto inserting of semi-colons after empty return) and source code routinely, intentionally getting mangled by minification.
- glitchc 2y ago> but nobody wants to say something positive about JavaScript... For obvious reasons...
- BeetleB 2y ago> now except now we also need a \ to make multiline expressions. You never need the backslash in Python to make multiple expressions. There's always a way to do multiline using parentheses. Their own style guidelines discourage using backslash for this purpose.
- taormina 2y agoAnd you can also do it with triple quotation marks if strings are involved, but it’s still more work for the compiler that someone explicitly did, it’s not magic.
- BeetleB 2y agoPlain strings work fine. Python has the same behavior as C: If two strings separated by whitespace, it concatenates them. So if I have a long string, I start with an open parenthesis, type one string, go to the next line, and another, and so on over several lines. Python sees it all as one string. Very readable.
- sokoloff 2y agoIf it’s in the language spec as required there and I’m using a compiler that claims to implement that language spec, I want the compiler to raise the error. Additionally offering help on how to fix it is welcome, but silently accepting not-language-X code as if it were valid language-X code is not what I want in a language-X compiler.
- nazgul17 2y agoIt's not that the semicolon is somehow a special character and that's why it's required/optional. It's the context that makes it necessary or not. Python proves that it's possible to design a language that doesn't need semicolons; it does not mean that e.g. Java or C are well defined if you make semicolons optional.