Hacker News new | ask | show | jobs
by dsymonds 3039 days ago
Good to see rustfmt arrive.

Sad that it is configurable, though. The biggest benefit of its predecessors such as gofmt is that they are not configurable, leading to a much more uniform formatting style and avoiding endless discussions about whitespace layout.

8 comments

I don't agree. There is a default configuration, and that configuration is very good (I've been following the process of nailing it down, and IMO it's been done very tastefully), and is the formatting used by official Rust codebases, lending it the weight of authority. I have no reason to configure it to do anything differently. But I also have no reason to forbid anyone else from formatting code as they please. What's the possible harm? If you're on a team, and you want code uniformity, you require the default configuration. If you're worried about pulling some random code and having it use {tabs|spaces} instead of {spaces|tabs} (which, btw, is, without hyperbole, the dumbest argument in the entire human history of programming) then you set your editor to run rustfmt on files before opening them.

The gofmt argument isn't the final word here. There's plenty of Go users who don't like gofmt's style, so they just don't use gofmt. It's easy to imagine other users who don't like gofmt's style, and don't like being pressured to use it, so they just don't use Go at all. How is that any better than just having a configurable tool with sane defaults? It's one thing for a tool to be opinionated; it's another thing entirely to be dictatorial and stubbornly inflexible.

>But I also have no reason to forbid anyone else from formatting code as they please. What's the possible harm?

Obviously the proliferation of coding formatting styles. It's not we didn't have "official styles" and formatting tools before for other languages.

The greatness of gofmt, and what people love it for, is how it killed all other options.

Not sure if it was actually that, many don't seem even aware of indent, whereas I used to work in places that executed it as CVS pre-commit hook.
"And guess what?" Richard angrily replies, "That's never going to happen now. Because there's no way I'm going to be with someone who uses spaces over tabs."

Man, there's something cathartic in seeing your industry and self-identified group's ridiculousness aired for all the world to see.

If rustfmt were not configurable, it would get a lot less use. Rust has been around for quite some time now, and there's a lot of code out there. We can't force anybody to run rustfmt, and if they don't like the results, they won't use it. It's not a choice between different code styles and a single code style; it's a choice between different code styles with a tool to keep things tidy and different code styles with a tool nobody uses. Things were different for Go for a variety of historical reasons, one important reason being that gofmt existed early on.

To take a concrete example, adopting gofmt's choice to not have a line length limit would have been a nonstarter, because lots of code out there uses long expressions manually wrapped to be readable. A lot of the work in rustfmt has gone into playing nicely with community conventions like these.

Agreed - I am an example. I had vim format my rust code on save, but there was one single bit of formatting which drove me nuts, so I turned the plugin off.
gofmt choice of not breaking lines is due to the fact that new lines in Go mean an implicit semicolon unless there is a comma or another continuation.

To break lines, the formatter would have to refactor code, which is not desiderable.

That would be an enormous problem for us. We need rustfmt to be configurable because it let's us use it to make MISRA-like style guidelines automatically enforceable for our codebase, which would be likely summarily rejected without them, so then we'd be forced to either do it manually or reinvent most of rustfmt ourselves.
Yeah, I'm not psyched about it either, but that ship has sailed.

The defaults are what's considered the "official" style; we expect the vast majority of people to use it. Defaults are powerful.

The only reason I don't use gofmt is because it is unconfigurable. And some of its defaults really stink. Kudos to Rust for getting this right.
I often have to zoom into code a lot more than others. This means that I will often want to format my code differently. I change the settings and I can use defaults before committing the code.

Programming causes me a lot of eye strain as it is, a configurable syntax formatter really does help.

I never see anyone discuss syntax the way you're describing. Not at work, not online. Actually the only place I see it is when discussing what the default is, so I think having a default is far more likely to cause those discussions as people will have more reason to complain.

I've never once seen or experienced any discussion about whitespace layout in Rust. OTOH, I've had several discussions about whitespace layout in Go in less than a year of programming in it due to gofmt not enforcing a maximum line length. Previous to writing Go, I worked on a C++ project that used clang-format (with a custom configuration), and we never had to have any formatting discussions because it also handled maximum line lengths.
Yeah, I guess that's the Rust way. The more options/configurations the better! Simplicity is not on the top list for sure.
We have a strong culture of convention over configuration; these two things are not inherently at odds.

To get the default formatting with rustfmt, you just run it. You can configure it via some file but I've never needed to. I don't even know what the options are.

Ok so what happens if I contribute to a open source project with my default fmt configuration if that project doesn't use the default configuration? Will people yell at me to "fix" the formatting?
That'd depend on the project, but even then, you'd just run `cargo fmt` and be done with it. That project would have a rustfmt.toml in the repo, so it would just make the changes for you.
Using default == Simplicity. You don't have to use the options.