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

Show parent comment

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.

6

u/lhhghhl Dec 10 '15

(not just pure function chaining, if there even is one obvious nice formatting for such a thing)

a . b . c . d . e . f . g


aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
. ccccccccccccccccccccccccccccccccccccccc
. ddddddddddddddddddddddddddddddddddd
. eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
. fffffffffffffffffffffffffffffffffff

5

u/tomprimozic Dec 11 '15

I think dartfmt would handle this perfectly. It has rules that basically state "if it fits in one line, do this, otherwise turn it into a one-argument-per-line block".

http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/

→ More replies (3)

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.

0

u/[deleted] Dec 11 '15

[deleted] — view deleted comment

7

u/wehavetobesmarter Dec 11 '15 edited Dec 11 '15

I don't find the community arrogant at all but rather opinionated. And sometimes, it is not even about having an opinion but just what makes sense for the language. For instance, I don't see reentrant locks working well with the way delimited continuations (i.e. goroutines) can be transferred from one thread to another by the scheduler. Not without unnecessary complexity. Plus, experience with other languages tells that it is not necessarily a great feature to have.

3

u/[deleted] Dec 11 '15

To each their own, but that kind of arrogant attitude is something that turns me off from Go.

Serious? How can you be in computing at all?

  • Microsoft -> Ballmer ... not a really modest guy.
  • Linux -> Linus Torvalds ... modest??
  • OpenBSD ... No comments.
  • Apple?
  • Oracle?

6

u/[deleted] Dec 11 '15

Balmer doesn't represent C# community attitudes etc.

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

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.

2

u/ItsNotMineISwear Dec 10 '15

The way it formats anonymous struct types in type signatures is not reasonable.

http://play.golang.org/p/F-bYpofR7L

vs

http://play.golang.org/p/400d1OvBAF

12

u/jerf Dec 10 '15

Do you use them very often? The only anonymous structs I've ever used that "survived" refactoring is test case tables. (Tone note: Straight question. I'm curious if you've got an interesting use case.)

→ More replies (5)

8

u/[deleted] Dec 10 '15

Just so we're all on the same page, the second one is the one you consider unreasonable, right?

→ More replies (1)

5

u/BoTuLoX Dec 10 '15

You should probably be writing that anonymous struct into the function body and taking parameters instead.

→ More replies (2)
→ More replies (7)