[rust-dev] RFC: Ignore trailing semicolons

Daniel Patterson lists.rust at dbp.mm.st
Thu Aug 2 10:37:42 PDT 2012

I personally think the current/old rule is good; at least to me, it is completely clear what is going on - semicolon means terminate statement, and the last (unterminated) statement is returned, unless a short-circuit return exists. Mixing functional/imperative code is tricky, but I think this rule actually works pretty well. Learning it took no time, especially compared to the other less-obvious syntax/semantics of rust.

Dropping return values seems like a solution to something that isn't a problem (and just makes things less clear/more bug prone) - because if I write:

fn something() {

and want it to return the result of the second function (and thus, intentionally leave off the semicolon) but forgot to write (or update, if it used to return unit) the signature, it will simply drop it. Whereas without dropping values, and with the current rules, this would be a compile error - meaning I either have to specify that I want to drop it explicitly, or fix the signature. This seems like a win.On Aug 2, 2012, at 1:35 PM, Patrick Walton wrote:

> On 8/2/12 9:52 AM, Glenn Willen wrote:
>> But now that I see that the new syntax is effectively the same one
> Perl uses, I'm not super worried about it, as long as we adopt the same
> house style that Perl programmers use: The semicolon is _always_
> present, except in cases where it's too ugly (which is to say, one-liners.)
>> (We could also adopt a house style of leaving it in where the value
>> is
> ignored, and taking it out where the value is used; but if we did that
> we might as well not change the syntax. ;-)
> I like the idea of having the trailing semicolon be our house style, except in the case of one-liners. I could rig up the pretty-printer to do that.
> Ultimately I think this comes down to the fact that we're bridging two worlds: we're trying to cater to the functional programming world, which is used to semicolon as a statement separator, and the C/C++ world, which is used to putting a semicolon at the end of every block.
> Patrick
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev

More information about the Rust-dev mailing list