Skip to content

Eliminating Semicolon need from Rust compiler #2583

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

Closed
AnirudhVyas opened this issue Nov 2, 2018 · 8 comments
Closed

Eliminating Semicolon need from Rust compiler #2583

AnirudhVyas opened this issue Nov 2, 2018 · 8 comments

Comments

@AnirudhVyas
Copy link

AnirudhVyas commented Nov 2, 2018

I am not too familiar with internals of Rust compilation, but I know that quite a few modern languages have adopted no semi-colons or just newline as a separation mechanism for "expressions" or statements or instructions written.

I do not know why Rust which is a good modern language would burden its users with such a thing - Though it is not much, but it makes code look less elegant and seems repetitive at best. Can we rid off semicolons altogether? How big of change would this be? I know it probably is not on greatest priorities of folks but smaller things like these matter quite a lot in making languages concise in my opinion. Less syntax more convention maybe...

Thank you.

@mark-i-m
Copy link
Member

mark-i-m commented Nov 2, 2018

There has been some discussion of this before (though I can't find the threads ATM), and the answer always seems to be that rust is opinionated in keeping semi-colons.

TBH, semi-colons are pretty important in rust. They are not just a terminator for the end of statements. They also signify tossing out a result. Also, I'm not sure if the grammar would be ambiguous without it.

@Diggsey
Copy link
Contributor

Diggsey commented Nov 2, 2018

Semicolons are not just a "line terminator" or "convention", they have semantics, which 1) cannot be replaced with line endings, and 2) should not be replaced with line endings, because it would obscure the meaning of the code.

All of your arguments against them are both subjective, and hard to relate to - semicolons are a one character operator, I really don't see conciseness as an argument against them. You could equally well argue for the * operator to be removed because it's verbose.

Even if this was desirable, it's just not going to happen as there is no compelling reason to break backwards compatibility in this way.

@memoryruins
Copy link

Currently, there are a few places in Rust where semicolons can be omitted, as noted, along with consequence of ambiguity, in the expression statements section of the reference:

An expression that consists of only a block expression or control flow expression, if used in a context where a statement is permitted, can omit the trailing semicolon. This can cause an ambiguity between it being parsed as a standalone statement and as a part of another expression

@H2CO3
Copy link

H2CO3 commented Nov 2, 2018

I do not know why Rust which is a good modern language would burden its users with such a thing

Because they are necessary for keeping the grammar whitespace-agnostic. Which in turn, is pretty much necessary for e.g. supporting macros and very useful for avoiding entire classes of bugs relating to inconsistent/surprising behavior of whitespace. Whitespace sensitivity is also often a source of complexity in the compiler and the cause of compiler bugs. Rust, as a language focused on safety and robustness while building large systems, can't afford that.

How big of change would this be?

As you can probably tell by now, pretty big.

smaller things like these matter quite a lot in making languages concise

Concision is not a feat unto itself. In this case, making statements one character longer improves understanding by a large margin.

(Furthermore, a subjective opinion: I'm always puzzled why people want to get rid of single character things pointing and saying "look it makes code so much shorter". I just don't see why that is much of an improvement, especially when it hurts readability more in other aspects.)

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

Here is some relevant previous discussion on this matter:

In any case, the semi-colon in Rust is significant, sometimes in subtle ways (e.g. rust-lang/rust#54782). I don't foresee a change like this being adopted. The only reason I haven't just closed this issue is that I am wondering whether we have a standard spot in the docs explaining why Rust doesn't use something like "automatic semi-colon insertion" like what JavaScript does? If we do have a FAQ entry or some other similar standard reference, I'd like to know what it is. And if we don't, we should add one, right?

@Centril
Copy link
Contributor

Centril commented Nov 2, 2018

@pnkfelix I think an entry should be added to https://www.rust-lang.org/en-US/faq.html (edit it here: https://github.com/rust-lang/rust-www/blob/master/en-US/faq.md). I've created an issue on the repo so I'll close this issue.

@Centril Centril closed this as completed Nov 2, 2018
@antonkulaga
Copy link

I think it is just a bad design decision to have semicolons and instead of recognizing it as a mistake the community rationalizes and tries to defend it. For instance, Scala does not have any semicolons and works really well, I have never had a problem with ambiguity because of the lack of semicolons in Scala.

@H2CO3
Copy link

H2CO3 commented Apr 3, 2020

Rust is nothing like Scala though. See my comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants