What do you think about less code? - Let's cut off the Semicolons!

Sorry, that I've to edit my first post,
but I can't reply to this topic anymore.

At first, thank you for all your replies
and it was definetly not my intention to hurt anyones feelings with this post.
So I hope no one took this too serious (pls don't front my punctuation ^^ this is not an master thesis :v:).

I knew from the very begining,
that this is more of an trivial post,
because you can't tell a spanish guy to only talk perfect portugese.
On the other hand was my intention to get in touch with the community (The ammount of activity is pretty cool).

Due to my employemend I worked a lot with the Erlang based programming language "Elixir".
Some time ago I searched for an more universal language so I researched and found Rustlang.
An Great language.

Now after I took some time to dive into it, I asked myself: Why are they still using Semicolons?
Aren't we much further beyond this old type of ending a line of code? What about the 0th Rule of UNIX-Users? (UNIX-Users are Lazy ^^ => so I don't want to write more code than I need to get my logic done)

So as an more practical example of my thought: In Rust you don't use a Semicolon in a Function if you want to return a value. You leave it open, so it can "flow" out of the function.
Compared to Elixir, it's pretty much the same, beside it's clear for the compiler, that only the last value or the last operation of an sequenz is returned.

So why use Semicolons if we don't use them continuously? Seems a bit ugly to me :v::sweat_smile:

And now some visual examples:
Done in Rust it will look something like that:

  fn run() -> &str {
    let first_name = "John ";
    let last_name = "Doe";
    let mut welcome_text = String::new("Hello ");
   // Add the Name to the "Hello " and returns it
  } // Will return: "Hello John Doe"

compared to Elixir, there I solve it like that:

  def run() do
    first_name = "John "
    last_name = "Doe"
    welcome_text = "Hello "

    # Returns "Hello John Doe" as it's the last value handled
    welcome_text  <> first_name  <> last_name

  end  # Will return "Hello John Doe"

Let's discuss wether we should use Semicolons in Rust or just cut them of
or even build a hybrid to let Developers choose their path .
Maybe there's an seriously thought behind the usage of Semicolons in Rust
or maybe it's just for the C/C++/C# Developers to get in easier.

Let me hear your thoughts..

1 Like

There have been previous discussions about this. It has several problems. For example what should

a = b

parse to? If it is newline insensitive then you get a = (b && c), while if it is whitespace sensitive you get a = b; &&c. Adding newline sensitivity would be a breaking change and the whitespace insensitive parse is just surprising.

(This is the users forum for usage questions. internals.rust-lang.org is the right place to suggest changes to the language itself)


is an example of a previous discussion.

is another.


This would be the worst kind of bikeshedding discussion: not only is it primarily about style, it’s also about changing part of the design that’s been settled for years. This sort of change would break all sorts of tools that parse Rust code, and so the benefits of implementing it would need to justify all of that community pain.

That seems unlikely in this case.

That wouldn't be the case if it's in the choice of the developer to choose his style
and you are still allowed to use semicolons.

No, every tool that parses Rust code now needs to have a significantly more complicated parser in order to handle both styles. Newcomers will be confused about the variance in style in the many code examples on the web (we see this already with the relatively minor 2015/2018 edition changes)— This sort of change has tendrils that reach far beyond any single piece of code.

1 Like

I understand what you are trying to say.
But I wouldn't like Rust having multiple styles/syntaxes achieving the same thing.

It's already hard enough to learn getting used to one style. Reading multiple examples in different styles and understanding them would make it 2 times harder. In my opinion.


I personally prefer to adapt to a certain programming language's style than adapt it to me, at the expense of making it more complicated / ambigious. I think it's good when a programming language is opinionated and has a clear single way of doing things. I like rustfmt for that reason too.


I can't help noticing that in your post you end sentences with a full stop. A "period" for our English challenged friends across the pond. Or basically ".".

Why do you do that? Aren't we much further beyond this old type of ending a sentence?

We have punctuation because punctuation carries meaning. Rust has it's punctuation with it's own meaning. Other programming languages have their own ideas about punctuation.

For example: I cannot fathom why Python has:
dispensed with semicolons,
dispensed with braces around conditionals,
dispensed with curly brackets or whatever for block delimiting,

but still requires the totally redundant colons, ":", in function definitions, conditionals and loops etc.



[moderator note: Let's not get into the rationale or pro/con of Python's syntax specifically.]


Sorry, yes, Python was not at all my point there.

Rather that every programming language makes choices about it's syntax. Likely for all kind of reasons that are not immediately clear to anyone coming across the language for the first time.

We just have to deal with it if we are chopping and changing languages. It's not even a big deal.

I don't like it when languages force me to split my long lines in weird places, which such languages are usually forced to force me to do.

1 Like

Oh no, not another instance of the "semicolons are just line endings" fallacy, please!

What do you think about less code?

First of all, I think raw character count is a spectacularly bad metric of code complexity.

Secondly, terseness for the sake of terseness, magic, and implicitness is inferior to explicitness in the overwhelming majority of cases (with some notable major exceptions).

The tedious, mundane aspects of programming, such as keeping syntactic and semantic rules in our head for correctness of the code, are already hard enough without the language planting footguns by actively encouraging the programmer to rely on some imperfect heuristic mechanism for guessing what s/he meant.

Please study the language and make sure you understand its basic concepts before making unfounded (and consequently wrong) assumptions about its elements. In Rust, semicolons are not "line endings". They serve multiple, related purposes (for instance, resolving ambiguities at statement boundaries as well as differentiating between statements and expressions), which I am not going to reiterate here in detail, as they are clearly explained in the relevant part of the Rust book.

1 Like

Hmm... that is an interesting point.

I have decided I don't want to think about fiddling with my code layout anymore. Which sometimes could waste a lot of time when I get OCD about lining things up, this way and that.

No, now I just cargo fmt. And boom it's done.

Maybe I don't agree with cargo fmt's choices sometimes. I let it be. In the belief that if all the Rust world used cargo fmt with out of the box configuration, then the consistency of formatting style is better for all of us in the end.

Of course, if Rust did not have those semi-colons and such then it might not be possible to have a cargo fmt that does what it does so well.


In favor of semicolons

To me semicolon is a legibility feature. It is a marking that defines the ending of a procedure or statement. As soon as it is read, one can expect for the next procedure in the next line. A cognitive related issue to me. Just like in written languages, eg. English, punctuation is necessary to establish the segmentation of sentences.

Understanding third-party code is already a challenge. The more features if favor of legibility the better, in my opinion.

An idea should be to allow semicolons to be optional, but keeping rustfmt still capable of accepting semicolons as default. See Javascript: semicolons are optional, Airbnb formatting style with Lint will enforce semicolons to mark the ending of statements and procedures.

My personal coding style is so close to what rustfmt suggests that I tend to not bother with setting it up, but even when using cargo fmt, the thing I type still has to be syntactically valid so the formatter can understand me.

1 Like

Javascript semicolons are optional. But as Douglas Crockford pointed out, omitting semicolons can have weird and unfathomable consequences. Consider:

function afunc () {
    return 2


function afunc () {

Spot the difference in output?


I just like the robustness of the fact that I can write 1000 lines worth of code in a single line in any .rs file and it works fine, and if I let rustfmt deal with it it'll come up with exactly one solution ¯\_(ツ)_/¯

I don't really understand why the semicolon is ever a talking point. I used to heavily use golang which didn't have any semicolons, and after starting rust I don't think the thought I don't like these semicolons has ever occured to me.

1 Like

I've got to add that I love how rustfmt allows me to be lazy about formatting, especially when I'm using voice coding. So nice not to have to line braces up myself.

1 Like

I've never actually seen voice coding in action. Do the tools have to be language aware, or are you just explicit about every piece of punctuation and spacing?