How do you format multy-argument function calls?


#1

How would you format a piece of code like

fn fun_with_too_many_parameters(s1: String, s2: Vec<i32>, s3: i32) {}

fn main() {
    fun_with_too_many_parameters(
        "Hello, World".to_owned(),
        vec![92, 92, 92],
        1 + 92 + 1 + 1 + 1 + 1,
    )
}

?

rustfmt currently formats it as

fn fun_with_too_many_parameters(s1: String, s2: Vec<i32>, s3: i32) {}

fn main() {
    fun_with_too_many_parameters("Hello, World".to_owned(),
                                 vec![92, 92, 92],
                                 1 + 92 + 1 + 1 + 1 + 1)

}

and I find this utterly unsatisfactory :slight_smile:

Is this a well established Rust style which I have to accept? I would really love argument per line, style to be the default in Rust :slight_smile:

See https://github.com/rust-lang-nursery/rustfmt/issues/566 for real world examples of the problem.

The rant was provoked by this beautiful talk about aesthetics in Python which I can’t recommend highly enough


Please help test Rustfmt
#2

In most languages I prefer the double-indentation and one-argument-per-line.

fn fun_with_too_many_parameters(s1: String, s2: Vec&lt;i32&gt;, s3: i32) {}

fn main() {
    fun_with_too_many_parameters(
            "Hello, World".to_owned(),
            vec![92, 92, 92],
            1 + 92 + 1 + 1 + 1 + 1
            );

}

The align-with-function-name (your second example) is IMHO one of the ugliest versions I’ve come across:

  • It requires to re-indent multiple lines if the function name changes. This causes lots of unnecessary diffs if you do a global refactoring.
  • In some way it encourages to unnecessarily keep function names short or use abbreviations, just to keep the rest from escaping the screen
  • For short function names it might even fall together with a normal 4-spaces-indentation, which makes the code harder to read.
  • It wastes lots of space

Everything IMHO :grin:


#3

I just wanted to mention the relevant timestamp: 35:04


#4

I prefer the one arg per line style too. I find it flows better. It’s more like ‘do this fn’ with ‘this arg’, ‘this arg’ and ‘this arg’. Rather than ‘do this fn with this arg’, and ‘this arg’ and ‘this arg’.

It’s all a matter of taste though :slight_smile: