[rust-dev] RFC: Ignore trailing semicolons

Glenn Willen gwillen at nerdnet.org
Thu Aug 2 09:52:05 PDT 2012


On Aug 2, 2012, at 9:13 AM, Patrick Walton wrote:

> If the semicolon were mandatory at the end of blocks, you'd have to write:
> 
>    let x = if cond { 3; } else { 5; }
> 
> Which would be a non-starter, IMHO.

So looking at this example made me realize that I do know one language that uses an optional-last-semicolon, which is Perl. And the house style there, which would probably come the house Rust style, is to use semicolons everywhere except one-liners like this.

I personally still favor the current style, where the semicolon-or-lack-thereof has to reflect the return type of the function, and it's unambiguous whether a function's return type is the type of the final expression, or unit. This seems especially important in the non-function-item cases where the type has to be inferred.

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

Glenn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 243 bytes
Desc: This is a digitally signed message part
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20120802/0125240c/attachment.sig>


More information about the Rust-dev mailing list