Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semicolon #1924

Closed
jloveric opened this issue Aug 5, 2022 · 7 comments
Closed

Semicolon #1924

jloveric opened this issue Aug 5, 2022 · 7 comments
Labels
leads question A question for the leads team

Comments

@jloveric
Copy link

jloveric commented Aug 5, 2022

Is the semicolon actually required? It is no longer required in javascript so it seems like you could get rid of it here.

@jonmeow jonmeow added this to Questions in Issues for leads via automation Aug 5, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Aug 5, 2022

I'm going to let the leads respond here.

For convenience I'll copy @josh11b's #1739 (comment):

My recollection of the reasoning behind required semicolons is:

  • matches C/C++
  • makes it easier for tools to parse and operate on source code
  • readability is more important to us than writability

That being said, we do want it to be as easy as possible to determine if a ; is missing for error detection and recovery and so things like IDEs can help put them into the code for you. That mostly impacts the rest of the grammar, though.

Incidentally, automatic semicolons are a stronger restriction on the rest of the grammar.

I would also like to note that the rules for automatic semicolon insertion end up complicated, and very different for different languages. We have a strong preference for simple rules, particularly at first. If something is shown to be a real problem in practice, we can always add complexity later.

Comments saying "I like X" or "I don't like X" don't really contribute to the conversation. Much more helpful would be a reason for or against X that hasn't already been considered.

@geoffromer
Copy link
Contributor

It's important to distinguish between two possible features here:

  • Some languages (such as Python, the C preprocessor, the BASIC family, and many others) treat a line break as ending a statement, usually with exceptions for things like lines ending in \ or lines with unclosed delimiters. In such languages, semicolons are never necessary, unless for some reason you need to pack multiple statements onto a line.
  • In JavaScript, every statement ends with a semicolon, but if (and only if) there's a syntax error in the code you wrote, JavaScript will attempt to recover by inserting semicolons at the end of lines. This means that if two adjacent statements would also be valid as a single statement, you must add a semicolon between them. It also means that you can't tell whether a line of code is a complete statement just by looking at that line, because it could depend on the contents of the following lines.

I tend to think the first approach isn't right for Carbon, but it's basically sound. On the other hand, the JavaScript approach is widely regarded as a mistake (even the original designer agrees), so Carbon definitely should not follow that example.

@chandlerc
Copy link
Contributor

The leads chatted and agree with the rationale write up by @josh11b that was quoted here. Marking this as decided "not planned".

@chandlerc chandlerc closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2022
Issues for leads automation moved this from Questions to Resolved Aug 8, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Aug 8, 2022

@chandlerc Should the decision to include semicolons be codified by a proposal?

@chandlerc
Copy link
Contributor

@chandlerc Should the decision to include semicolons be codified by a proposal?

If it isn't already covered by a proposal around statements, yes, it should. (I thought it might have already been covered, but haven't checked thoroughly...)

@chandlerc chandlerc moved this from Resolved to Needs proposal in Issues for leads Aug 8, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Aug 8, 2022

I may be wrong here, but I don't think we've had one -- https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/blocks_and_statements.md has no references.

@jonmeow jonmeow added the leads question A question for the leads team label Aug 10, 2022
@jonmeow
Copy link
Contributor

jonmeow commented Aug 11, 2022

Filed #2002 to track the proposal need.

jonmeow added a commit that referenced this issue Mar 16, 2023
Statements, declarations, and definitions will terminate with either a semicolon
(`;`) or a close curly brace (`}`). Semicolons are never optional.

For example, with a semicolon, `x = x + 2;`. With a close curly brace,
`for ( ... ) { ... }`, or `class C { ...}`.

This does not affect any approved proposal; rather, it makes an important
assumption explicit.

Based on lead decision #1924

Fixes #2002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
leads question A question for the leads team
Projects
No open projects
Issues for leads
Needs proposal
Development

No branches or pull requests

4 participants