Leading commas in Rust like in Elm

I like the leading commas in Elm. Is it possible to use them in Rust and set up the formatter to accept them?

I also want the brackets/braces in the first line, like in this example. I think it just looks much cleaner.

No, but you can use trailing commas, so spurious VCS changes are not an issue.

1 Like

Conversely I find leading commas loathsome. Nobody would write like that in English or other languages. Why would want that misformatting in a programming language?

Anyway, never mind what you or I find preferable. I think it would be great if the entire Rust world would just use the formatter as is, out of the box, then the global Rust community has a common standard. With that reading other peoples code will not be jarring or surprising for anyone.

1 Like

It has, but nuances that matter a lot for readability are almost impossible to enforce automatically. There is basically complete agreement in the basics (indentation, use of whitespace, formatting of declarations, case conventions), and it doesn't hurt for a human to be permitted to exercise good taste if they want to.

1 Like

Why would I care? Code isn't English, it's closer to a formula. And English isn't even a native language for most people in the world, yet they still have to endure progamminglish, just because some people say so.

That speaks more about how close your taste is to the current community conventions than about some deep truth or deep commitment on your part. No surpsrise, since Rust's syntax and style were deliberately made similar to the popular C++ and Java conventions.

1 Like

That seems like a weird statement. Having a strong community convention for style is a quite often held preference, nothing unusual. They never claimed it was a "deep truth or deep commitment" afterall.

1 Like

Hmmm... That is for sure true. However a high level programming language is an adapter between the high level abstract thoughts of people to the low level bits and bytes that a machine understands. As such we would expect it to have some relation to a language as known by humans. In its keywords and grammatical structure. As it happens Rust was created by an English speaker so no surprise it has a hint of English in it.

Who says so? I'm not aware of any dictators mandating the use of English in any programming language. It's not like Russia dictating that Ukrainians speak Russian for example.

Indeed. No doubt my emotional response to any programming language or it's formatting style is biased by my previous experience. Like most people I imagine. However there are a bunch of different formatting styles in use in C/C++, some I like, some I don't. I don't let it bother me, I just use whatever the team I'm working with uses. I'm not going to kick up a fuss about it. I flinch at some things the Rust formatter does, but still think it's better for all of us if we go with the flow.

Anyway, you got me thinking about that "progamminglish" thing. I mean, English is a mongrel of a language. A mash up of the languages of various invaders and occupiers over the centuries. A quick google throws up the following origins for the words used in Rust:

“if” : Germanic.

“where” : Saxon.

“function” : Latin.

“loop” : Norse.

“for” : Indo European.

“match” : Germanic.

“move” : Latin.

“await” : French/Latin.

“asynchronous”: Greek.

“return”: Latin.

“use” : Latin.

“crate” : Latin.

Seems Rust has been fairly inclusive linguistically. I'm sorry you have to "endure" that.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.