Rust Programming Language Announces New Team to Evolve Official Coding Style (rust-lang.org) 66
"The Rust programming language is getting so popular that the team behind it is creating a team that's dedicated to defining the default Rust coding style," reports ZDNet:
Each language has style guides and, if they're popular enough, may have multiple style guides from major users, like Google, which has its guide for C++ — the language Chrome is written in. Python's Guido van Rossum's posted his styling conventions here.
Rust, which reached version 1.0 in 2015, has a style guide in the "rustfmt" or 'Rust formatting tool' published on GitHub. The tool automatically formats Rust code to let developers focus on output and aims to reduce the steep learning curve confronting new Rust developers. The guide instructs developers to "Use spaces, not tabs" and says "each level of indentation must be 4 spaces", for example....
But the team responsible for writing the style guide between 2016 and 2018 has "by design" come to end, so now it's now been decided to create the Rust style team, consisting of Josh Triplett, Caleb Cartwright, Michal Goulet, and Jane Lusby. The crew will first tackle a "backlog of new language constructs that lack formatting guidance" and move on to "defining and implementing the mechanisms to evolve the default Rust style, and then begin introducing style improvements."
The work includes minor language changes, big structural changes, and backwards compatibility and the style team wants to craft the tool to make it current for easier coding in Rust, and help adoption.
New constructs "by default, get ignored and not formatted by rustfmt," according to a blog post by the Rust style team, "and subsequently need formatting added. Some of this work has fallen to the rustfmt team in recent years, but the rustfmt team would prefer to implement style determinations made by another team rather than making such determinations itself."
The post also notes that the backwards compatibility maintained by rustfmt "also prevents evolving the Rust style to take community desires into account and improve formatting over time." rustfmt provides various configuration options to change its default formatting, and many of those options represent changes that many people in the community would like enabled by default... but [rustfmt] cannot make this the default without causing continuous integration failures in existing projects. We need a way to evolve the default Rust style compatibly, similar in spirit to the mechanisms we use for Rust editions: allowing existing style to continue working, and allowing people to opt into new style.
To solve both of these problems, RFC 3309 has revived the Rust style team, with three goals:
- Making determinations about styling for new Rust constructs
- Evolving the existing Rust style
- Defining mechanisms to evolve the Rust style while taking backwards compatibility into account
We don't plan to make any earth-shattering style changes; the look and feel of Rust will remain largely the same. Evolutions to the default Rust style will largely consist of established rustfmt options people already widely enable, or would enable if they were stable. We expect that the initial work of the style team will focus on clearing a backlog of new language constructs that lack formatting guidance. Afterwards, we will look towards defining and implementing the mechanisms to evolve the default Rust style, and then begin introducing style improvements.
Rust, which reached version 1.0 in 2015, has a style guide in the "rustfmt" or 'Rust formatting tool' published on GitHub. The tool automatically formats Rust code to let developers focus on output and aims to reduce the steep learning curve confronting new Rust developers. The guide instructs developers to "Use spaces, not tabs" and says "each level of indentation must be 4 spaces", for example....
But the team responsible for writing the style guide between 2016 and 2018 has "by design" come to end, so now it's now been decided to create the Rust style team, consisting of Josh Triplett, Caleb Cartwright, Michal Goulet, and Jane Lusby. The crew will first tackle a "backlog of new language constructs that lack formatting guidance" and move on to "defining and implementing the mechanisms to evolve the default Rust style, and then begin introducing style improvements."
The work includes minor language changes, big structural changes, and backwards compatibility and the style team wants to craft the tool to make it current for easier coding in Rust, and help adoption.
New constructs "by default, get ignored and not formatted by rustfmt," according to a blog post by the Rust style team, "and subsequently need formatting added. Some of this work has fallen to the rustfmt team in recent years, but the rustfmt team would prefer to implement style determinations made by another team rather than making such determinations itself."
The post also notes that the backwards compatibility maintained by rustfmt "also prevents evolving the Rust style to take community desires into account and improve formatting over time." rustfmt provides various configuration options to change its default formatting, and many of those options represent changes that many people in the community would like enabled by default... but [rustfmt] cannot make this the default without causing continuous integration failures in existing projects. We need a way to evolve the default Rust style compatibly, similar in spirit to the mechanisms we use for Rust editions: allowing existing style to continue working, and allowing people to opt into new style.
To solve both of these problems, RFC 3309 has revived the Rust style team, with three goals:
- Making determinations about styling for new Rust constructs
- Evolving the existing Rust style
- Defining mechanisms to evolve the Rust style while taking backwards compatibility into account
We don't plan to make any earth-shattering style changes; the look and feel of Rust will remain largely the same. Evolutions to the default Rust style will largely consist of established rustfmt options people already widely enable, or would enable if they were stable. We expect that the initial work of the style team will focus on clearing a backlog of new language constructs that lack formatting guidance. Afterwards, we will look towards defining and implementing the mechanisms to evolve the default Rust style, and then begin introducing style improvements.
In a freeform language... (Score:1)
.... there shouldn't be an "official" coding style. If you want to make people write code in a specific layout then enforce it in the language parser like Python with its whitespace, otherwise butt out and let people make their own choices.
Re:In a freeform language... (Score:5, Insightful)
Ok guy whos never worked in a team before.
Style guides are good things. Theres nothing more incomprehensible than code maintained by 4-5 people each with their own whackadoodle idea of how to format code.
Re: (Score:1)
Source code formatting is very low on my list of factors for maintainable and reliable code. Put whatever you want in the .editorconfig file to end the bike-shedding, and start writing code.
Re: (Score:1)
Style guides are more than just source code formatting.
They encode naming conventions, higher level constructs (e.g. JavaBeans), comment styles, etc.
Things are much easier to understand when there's consistency.
Re: In a freeform language... (Score:1)
Format-Style-Syntax. Pretty important in system level coding.
Re: (Score:3)
The point of a coding style is to promote easier understanding of the code for humans while making it easier to spot errors. There are times where "special case" formatting makes the code much easier to understand and requiring it to be formatted in a way that makes it harder to understand is stupid.
Also, if your language requires compliance to an official style guide, it's garbage.
Re: (Score:2)
But auto formatters are always zero exception. Make a readable table, with one item per row and columns that line up, and then the auto-formatter will come pack everything to the line length limit and wrap it where ever. Becomes unreadable.
I think the reason some people need zero-exception strict style guides is that they can't actually write code in any kind of style themselves. Don't even know what the space bar, tab key, and enter key are for. The must have an auto formatter do this for them. It's l
Re: In a freeform language... (Score:2)
Re: (Score:1)
With the ubiquitous use of widescreen displays, I always turn off line length in all code formatting tools I use anyway.
That's you being short-sighted. They're not ubiquitous, and even if they were, assuming all of them are in use in landscape mode is just as silly and restricting on those of us preferring more vertical than horizontal space.
I for one have one 5:4, three 4:3, and no widescreens in use. But even if, my default xterm size would still be 80 columns, possibly switchable to 132.
The reasons to stick with 80 columns have little to do with the display: Very long lines aren't easy to read, the optimum seems to be a
Re: (Score:2)
You can mark sections of code that avoid autoformatting. And it's certainly useful at times, when e.g. a table layout for constants work out great.
Re: (Score:3)
Style guides are good things.
I don't entirely agree. Automatic style enforcement is a good thing. They are great at squelching the vast amounts of tedious bikeshedding that goes on arguing about style minutiae on every single PR.
Theres nothing more incomprehensible than code maintained by 4-5 people each with their own whackadoodle idea of how to format code.
For me only if it's truly whackadoodle. GNU style guide, lookin' at you...
As a certified old fart by the standards of IT, I've worked in enough differ
Re: (Score:2)
As a certified old fart by the standards of IT, I've worked in enough differently formatted codebases that I just forgot to care any more.
This is pretty much me as well. Where I work we have an "official" corporate style guide which I follow for new projects, but we also do a lot of sustainment work on stuff that came from acquired companies that did things their own way, and no one's going to go back through and change thousands of lines in an established avionics firmware package that was tested and sig
Re: (Score:2)
Where I work we have an "official" corporate style guide which I follow for new projects, but we also do a lot of sustainment work on stuff that came from acquired companies that did things their own way, and no one's going to go back through and change thousands of lines in an established avionics firmware package that was tested and signed off years ago just to make it jive with the style guide.
I too work on a codebase that's been amalgamated from a bunch of in house teams, predating the current guides pl
Re: (Score:1)
Where I've worked with project with extensive style guides, apart from what is enforced by a style linter, just leads to continual argy-bargy in code reviews. So tedious. Who can remember all
Re: (Score:3)
Re: In a freeform language... (Score:2)
I was working into teams probably before you were born feotus. I'm simply saying the language authors should stay out of it.
Re: (Score:2)
No, they shouldn't stay out of it.
Almost every project in the real world has a coding style standard, and you're stuck adjusting to that no matter what.
Every time you switch jobs or even projects within one company, now you've got to adapt to a different set of rules even if you're using the same language. That's a royal pain in the ass. It's better to just have one universal coding standard. An added advantage is that only one small team of language developers have to waste time haggling over exactly what
Re: (Score:2)
There's no point having freeform languages if you have One True Coding Style. Also certain coding styles such as mil spec ones can be rather awkward and wouldn't be popular in commercial enviroments.
Re: (Score:2)
There's no point having freeform languages if you have One True Coding Style
Why not? Take the example of Go, one of the most recent popular languages. It has one true coding style, and that gets enforced by the formatter utility, not the compiler. It was created by industry bigwigs with decades of experience. What makes you think that they are wrong and you are right?
Also certain coding styles such as mil spec ones can be rather awkward and wouldn't be popular in commercial enviroments.
At least the military gave up on creating new programming languages out of whole cloth and then foisting them on everyone, but they obviously have more work to do.
Re: (Score:2)
Sure, people who work together closely should use a common coding style. But the style shouldn't be enforced by the language; it should be the choice of the team, company or project, based on their own culture, history, the tool sets they use, general company-wide rules and so on. There are many factors that drive the choice of a particular coding style for a particular project, and the language team has access to none of them.
In the end, all the language team should do is suggest some guidelines, while ma
Re: (Score:3)
Why not? Why not have an official style used internally by the team to ensure consistency?
And then use the official style in the documentation when showing examples, as well, so all the examples have a uniform look.
Just because the language lets you put brackets and brace
Styleguides are like roads, bridges, and sidewalks (Score:4, Interesting)
Nearly all Java written in the last 25 years looks the same because in 1997 Sun created a coding standard that is universally enforced. All methods and variables use camelCase. All constants are in UPPER_CASE. Only one variable declaration is allowed per line. It annoyed me when I started learning it, but I grew to appreciate it when I inherited code from someone I have never met who left the company.
I get code from people across the globe who I have never met and often no longer are employed at my employers. I can read it effortlessly.
JavaScript? not so much...Python?...oh, hell, no!!!! I've seen some Python that is sensible and some that looks like it was coded by drunk monkeys. If there is a coding culture in Python, apparently no place I've ever worked at has hired developers who know what that is.
People hate on Java because it can be verbose and it is constricting, but that constriction means you spend more time thinking about business and less about trying to figure out what your coworkers are doing. Coding conventions and general culture are like sidewalks, bridges, and roads. They make everything easier and more efficient. You technically don't need them, but you'll get a lot more done a lot faster and more safely with them. If Rust wants to be a serious language for people who actually make money, they need a strong culture more than strong technology. No one cares if your code runs 5% faster if it costs 5x as much to write and is delayed 5x as often and has 5x as many bugs introduced by developers not communicating well with one another.
Re: Styleguides are like roads, bridges, and sidew (Score:1)
Being verbose while trying to figure out web standards in a language that changes to accommodate web standards? Every time a new library is thought up your old logic blows up. I'm not a java person though....to me java is actually all style and politics. But then you don't write device drivers with it either.....
tabs by default (Score:2)
Hopefully we can finally be treated like adults and have tabs be the default.
Clinging to the argument of universal formatting is weak. We have good tools and deserve a world that can better cater to the end user-preferences. gofmt has done the world a service by demonstrating how practical and scalable this choice was.
Also, accessibility matters [reddit.com].
Re: (Score:2)
I almost want to sponsor a study to see how much more energy and cumulative storage is required for spaces vs. tabs. Those extra bytes aren't free!
(I've never encountered, in more than twenty years of software development, a serious issue arising because code "wasn't readable due to formatting". Maybe I'm spoiled by working with people who can understand code regardless of an odd space here or there? Or perhaps because we relied on static checkers and actually read warnings, and had robust unit and integra
Re: (Score:2)
I've never encountered, in more than twenty years of software development, a serious issue arising because code "wasn't readable due to formatting".
Indeed, a good programmer will be amendable to variation, but there is research that has quantified the level to which this slows down a developer and it's not nothing, increasing inverse to experience (sorry I don't have enough time to dig it up right now). Further, it's important to consider that in today's world, developers work on more codebases and their positions are more fluid than ever before. The person that wrote a project may not even be on the team a year later, and no one knows the skill level
Re: (Score:2)
By all means do the math, but from a practical standpoint it just doesn't matter. You can always just convert (which can probably be distilled to a single command or click in your IDE) and then convert back again, so you can work with whatever your preference is.
I prefer to use all spaces and no tabs, unless I'm using a word processor or other DTP software and I am defining my own tabs for columnar purposes. Then the tab key does what I actually want it to every time, and I can also have half-indents if I w
Re:tabs by default (Score:5, Insightful)
Hopefully we can finally be treated like adults and have tabs be the default.
That link is very sobering. Unfortunately, the summary makes it clear that tabs are out.
From your link, for the benefit of others who won't bother to click:
Nobody talks about the real reason to use Tabs over Spaces
i've been slightly dismayed, that in every tabs-vs-spaces debate i can find on the web, nobody is talking about the accessibility consequences for the visually impaired
let me illustrate with a quick story, why i irrevocably turned from a spaces to tabs guy
i recently worked at a company that used tabs
i created a new repository, and thought i was being hip and modern, so i started to evangelize spaces for the 'consistency across environments'
i get approached by not one, but TWO coworkers who unfortunately are highly visually impaired,
and each has a different visual impairment
one of them uses tab-width 1 because he uses such a gigantic font-size
the other uses tab-width 8 and a really wide monitor
these guys have serious problems using codebases with spaces, they have to convert, do their work, and then unconvert before committing
these guys are not just being fussy — it's almost surprising they can code at all, it's kind of sad to watch but also inspiring
at that moment, i instantaneously conceded — there's just no counter-argument that even comes close to outweighing the accessibility needs of valued coworkers
[...]
is there really any reason, in favor of spaces, that counter balances the negative consequences for the visually impaired?
cheers friends,
Chase
Re: (Score:2)
It's much harder to convert spaces to tabs than it is to convert tabs to spaces.
Re: (Score:2)
I just had some beers so I'm not going to think about regular expressions right now and embarrass myself, but it seems pretty simple to use one of them to do that job and only convert the leading however many spaces to tabs, as many times as necessary per line.
More relevantly though, with modern coding standards checkers you can just have the code indented automatically and consistently to whatever standard is defined. So it's a good reason to either follow an established format, or establish one and write
Re: (Score:2)
The problem is that the number of spaces per tab can vary. With tabs to spaces, it's a preference set once. With spaces to tabs, well, it's anyone's guess. You could lean on pretty printers I guess, but you give up any advantage there might be for occasionally breaking convention for readability.
The AC's claim was "There's zero reason to use tab characters" On the contrary. If you want to lean on automatic formatting to suit individual developer preferences, using spaces never makes sense. Tabs have cl
Re: (Score:2)
I can see absolutely no reason to prefer spaces for indenting.
It lets you do half-indents, which are sometimes preferable for style reasons. Again, as long as formatters exist, it's irrelevant what your preference is. Pick one and use it, then run it through the formatter when you're done.
Re: (Score:2)
as long as formatters exist, it's irrelevant what your preference is
I very strongly disagree, for reasons I've already stated. You should as well, for the reason you've just given.
It lets you do half-indents, which are sometimes preferable for style reasons.
While I have no idea under what circumstance you'd want a 'half indent', it seems to me that the old rule of tabs for intending, spaces for alignment would solve that problem very neatly.
Re: (Score:3)
"especially trying to line things up vertically"
The answer there is that a text file is a bad format for non-text. Use a tool appropriate to the task.
Re: (Score:2)
That isn't a problem if we're talking about code. The rule was always tabs for indenting, spaces for alignment.
Re: (Score:2)
I too bemoan the overtaking of software by the space cadets.
Lost in this debate as always, as each camp attempts to place blame on the other, is where the blame really ought to be: The editor.
I get the universal formatting argument. My tab expansion may not be yours. The other side doesn't get the ease of editing argument--the cursor tapping through all your spaces is annoying.
The solution is simple: When loading the file, the editor should analyze the indentation and check to see that it follows a patt
Re: (Score:1)
I propose a similar, yet different solution: auto-format to your preference on pull / clone / checkout ( IDE formatter ) and auto-format to the guidelines on commit ( commit hooks ?).
Best of both worlds.
Re: (Score:2)
Yes! A source control script might be an even better option, since AFAIK you could deliver this feature to almost everybody with just a few source control systems, whereas there are a lot more editors. If you patch svn, git, and good ol' cvs, you cover what... 95% or more of developers? Sure there is probably a long tail of version control systems too, but if you got a feature like that in to the top 3 the rest would catch up. Additionally they tend to be F/OSS whereas MS's development environment is cl
Much like C++ and Java (Score:1, Troll)
Rust only has two major issues: Its conceptual design, and its implementation.
News (Score:1)
I like how "some people from an esoteric language have decided to extend an existing style guide to cover new language features" is considered as newsworthy here.
Can I also submit an article whenever I plan to cut my toenails or swipe my terrace?
Re: (Score:2)
Can I also submit an article whenever I plan to cut my toenails or swipe my terrace?
Sure, if your toenails are being used in the Linux kernel.
Re: (Score:2)
Rust isn't that esoteric. I've tried it twice. The first time I bounced (poor language documentation), Recently I tried again, and this time I managed it. Well, in the sense that I could actually do what I tried to do. But the libraries I need still aren't present. I'd do better with go, though I hate their development environment. Eventaully, though, I narrowed things down to Python or Java, because of the ability to have the same program run on different systems. Currently I'm trying Java, even th
Re: (Score:2)
Tuples, when I got around to researching that point, didn't seem to have ANY advantage over the custom class. And a few disadvantages (like not being able to choose the variable names).
Official guide? (Score:2)
Fine, but don't put too much effort into it. Let organizations define their own style rules, and automate them using standard tools.
Different groups have different ideas, and sometimes genuinely different needs.
spaces vs tabs? (Score:1)
They chose to codify using spaces versus tabs for indenting, which just reeks of amateur hour. It's what drives me crazy about Python, where it's even worse when people do that because of the silly way Python treats whitespace as flow control. Merging different codebases is a nightmare. With tabs, no one cares that your editor is setup for 4 spaces per tab and theirs is set up for 2, it all just looks like everyone thinks it should and it works. Spaces are inflexible, and there's no good argument I can make
Re: spaces vs tabs? (Score:2)
Amateur hour to enforce spaces? In all my 20yr professional life as a developer I've only ever seen enforced spaces. I don't think "amateur" is the word you're aiming for.
The ewhac 2021 C Coding Style Guide (Score:2)
The ewhac 2021 C Coding Style Guide. [ewhac.org] Adopt no substitutes.
I've been fiddling with Rust off and on for the last year, and I'm still trying to work out how I want the code to look. Naturally, my preferences are informed by my preferences in C coding style, but one principle, I think, stands above all others:
Don't make me hunt for important things.
Rust's syntax is very fiddly and has lots of details, most of which are significant. It will be a challenge to work out a style that lets all of those det
Re: (Score:2)
Don't make me hunt for important things.
One of the fundamental principles: Make everything important obvious. If it is not by itself, add something to make it as obvious as it should be. That is, for example, why an emergency shut-off is a big red button easily visible and usually breaking the aesthetics.
Rust's syntax is very fiddly and has lots of details, most of which are significant.
That does not sound good. In fact is sounds like an accident waiting to happen, especially in this combination. Second-system-effect?
So is it being "defined", or "evolved"? (Score:2)
What? Why not the CoC? (Score:2)
Because that one is wayyy more important than some technical details, right?
Seriously, all this shows is how immature that language is.
Unenforced code style (Score:1)
Unenforced code style boosts creativity and personal expression (art).
Why make the language free-form? (Score:2)
I know this is just a guide, but, if you want to recommend or enforce a style, make it part of the language definition; that's not difficult.
As several people have already said, you can always run a program you don't like through a formatter to achieve any desired format, and there are probably programs to rename non-global variables to conform to your chosen convention.
As also said, this is all bike-shedding; the real thing that needs control, and is hard, is stopping bad programmers writing bad code. Som
Sack them (Score:2)
Anyone that sits down and thinks "the best use of project time is to write a document telling everyone else to type their code the way I like it" should be removed from the project and never, ever, allowed back in.
We're not punching Fortran into cards anymore; our team can use the style that we like and you can stuff yours where the sun never shines (Belfast).
Can Someone Explain why Anyone would use Spaces??? (Score:2)
I have seen arguments, I literately asked my professor, but never gotten a real reason.
Tabs, by definition are literally the exact thing you want for indentation, they are indentation by definition. A system and program independent universally recognized indentation. Any uses of spaces is literally just hacked together sort of tab emulation. At the end of the day it looks identical, but is just harder to work with, transfer files between people, needs way more back end coding to work right, and literally bl
Re: (Score:1)
Re: (Score:2)
I see.
While your code might look stupid to you on your peer's computer, Would it not look good to him?
Or is it that 4 spaces looks better in notepad or Microsoft Office than 1 tab?
Re: (Score:2)
The problem is that tabs are historically 8 spaces but people want to use them to mean 4 spaces sometimes and this only causes problems.
If you use tabs and want them to work reliably they have to be 8 spaces, and 4 spaces seems to be the optimal indent level for code.
Re: (Score:2)