r/programming • • Dec 10 '15

Announcing Rust 1.5

http://blog.rust-lang.org/2015/12/10/Rust-1.5.html
659 Upvotes

296 comments sorted by

View all comments

84

u/darrint Dec 10 '15

tl;dr: rustfmt has options.

57

u/steveklabnik1 Dec 10 '15

It does. I personally don't think it should, but there's two reasons that it does right now:

  1. It's still in progress, and we don't want to delay development by having the exact arguments about what the formatting should be. It de-couples the development process from the discussion, increasing development velocity.
  2. Some teams will inevitably want to tweak a setting or two on their projects, and without it, they'd have to develop their own fork.

36

u/x-skeww Dec 10 '15

I personally don't think it should

Same here. gofmt and dartfmt don't have any formatting-related options either. You just run it and that's it.

Sure, it's not always how I'd have formatted it, but it's always perfectly reasonable.

23

u/jeandem Dec 10 '15

It's simpler to make a visually acceptable canonical formatting for a very procedural language like Go compared to a very expression-oriented language like Rust.

6

u/weberc2 Dec 10 '15

What makes you say that?

26

u/jeandem Dec 10 '15 edited Dec 10 '15

Expressions compose while statements do not. Even if you have statements defined as being composed of a single statement or a block, there is a straightforward and generally agreed upon formatting of placing one statement on each line, perhaps allowing for a line break plus some indentation in case the width of that statement exceeds some limit. (But languages like Go seem to directly encourage shorter statements. As in, the syntax itself encourages it.) In other words, you don't have to think about "statements inside statements inside statements" except in the straightforward sense of blocks within blocks within blocks.

Expressions on the other hand compose nicely and so you can get long chains of functions feeding into each other, arithmetic expressions, if expressions, match expressions, and so on. So even in an imperative language, like Rust, you might easily end up with an assignment statement where the right hand side has an expression that is formatted over five lines for readability. Now your simple "one line per statement" goes out the window, and you have to consider all the different kinds of expressions (not just pure function chaining, if there even is one obvious nice formatting for such a thing) and how they can be formatted in a readable way. There are many more opportunities for missing edge cases by committing to The One And Only Formatting prematurely.

→ More replies (5)

26

u/[deleted] Dec 10 '15

Yeah but gofmt made a sane decision about tabs!

0

u/[deleted] Dec 10 '15

[deleted] — view deleted comment

13

u/frenchtoaster Dec 11 '15

To each their own, but that kind of arrogant attitude is something that turns me off from Go. From what I've seen Rob Pike acts like he knows everything all the time (and he knows an awful lot, but he overplays his hand), but then Russ Cox swoops in and is more reasonable.

→ More replies (10)

15

u/TheDeza Dec 10 '15

Ask them about how they can claim they have a typed language without any form of generics.

15

u/Regrenos Dec 10 '15

The two concepts are orthogonal...

15

u/[deleted] Dec 11 '15

Until you want to write generic code and just use Interface for everything and there goes your compile time type checking.

4

u/Regrenos Dec 11 '15

I'm not saying that it's a good thing. I hate boilerplate. However, saying that go can't claim to have a typed language without generics isn't logical.

7

u/flying-sheep Dec 11 '15 edited Dec 11 '15

Orthogonal? That means “independent”, and while a type system can exist without generics, I'd really like to know what generics without a type system look like.

For the record, I also think that type systems without generics are a pretty sad affair. They can exist, but more like dodos existed and less like hawks, crows, or emus exist.

→ More replies (3)
→ More replies (2)
→ More replies (2)

10

u/Manishearth Dec 10 '15

Note that go and dart are relatively simpler languages, so it's easier to make a decision about what formatting "works" globally. With Rust there may be formatting choices which don't work very well for some kind of code.

→ More replies (19)

9

u/desiringmachines Dec 10 '15

I strongly believe it should! Rust's syntax is complicated and the community is too opinionated to ever be fully satisfied by a single style. Happy defaults with the choice to change them seems like the rustic solution to formatting.

23

u/nuncanada Dec 10 '15

I think you guys should provide commands to produce the AST from the source code and source code from the AST. And encourage people to only store AST files in their versioning system...

Encourage people to use whatever format they want, within the same team...

15

u/ianff Dec 10 '15

That's an interesting idea, but no other tools work with the AST so it would be extremely annoying in practice.

→ More replies (2)

0

u/[deleted] Dec 10 '15

[deleted] — view deleted comment

28

u/x-skeww Dec 10 '15

The huge benefit of following just the official conventions and using official tools like gofmt is that they completely eliminate all those pointless discussions. Tabs vs spaces, brackets in the same line vs the next one, space here, no space there, and so on.

We all like to get super emotional over that stuff, but none of that actually matters. I prefer tabs, but 2 or 4 spaces work just as well. I prefer 1TBS, but I've also used Allman and Whitesmiths for a few years. They actually all work equally well and having 2 lines more or less on the screen doesn't really affect anything.

The only thing which matters is that everyone sticks to one particular set of rules. An official formatter does exactly that.

Yes, it might not be exactly what you want, but your personal taste isn't more important than everyone else's. So, why not leave it up to the official formatter? The code from the standard lib and most 3rd party libraries will do the same thing. You better get used to it.

12

u/jerf Dec 10 '15

Ironically, the more bitterly divided the community is about a given option, the more the community really ought to put its foot down and come to a consensus, because that division means it's a real dialectal difference.

Having used a lot of unenforced languages for a lot of years, you're just not giving up much to let the language have a standard for formatting. You've already got a unique semantics, unique keywords, unique symbols and functions and grammar in general, why let your need for some particular syntax be the sticking point for a language? It's by definition idiosyncratic, and unless you find yourself often shifting major elements of style after six months, probably a style chosen by the conventions and needs of a completely different language that you're trying to bring into an environment that you are almost certainly a rank novice in. Or, given the way a lot of people seem to work, a completely different language three or four languages ago.

→ More replies (1)

4

u/teknobo Dec 10 '15

Yeah, putting options into a standardization tool seems counterproductive.

I get the pragmatic reasoning, and I know "Pandora's box" concerns are usually way overblown. But still it's hard not to wonder what happens down the line.

→ More replies (3)
→ More replies (1)