Rfcs: Eliminating Semicolon need from Rust compiler

Created on 2 Nov 2018  ·  8Comments  ·  Source: rust-lang/rfcs

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.

Most helpful comment

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.

All 8 comments

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.

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.

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

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.)

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?

@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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mahkoh picture mahkoh  ·  3Comments

3442853561 picture 3442853561  ·  3Comments

onelson picture onelson  ·  3Comments

silversolver1 picture silversolver1  ·  3Comments

mqudsi picture mqudsi  ·  3Comments