Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adhere to tidyverse style guide #16

Closed
wants to merge 1 commit into from

Conversation

krlmlr
Copy link

@krlmlr krlmlr commented Aug 14, 2023

@lionel-
Copy link
Owner

lionel- commented Sep 28, 2023

After having written some Typescript and Rust code, I think balanced delimiters are probably more conventional overall?

@krlmlr
Copy link
Author

krlmlr commented Sep 29, 2023

I no longer have a strong preference, I have settled for whatever the tidyverse style guide suggests. Are you willing to reopen that discussion upstream? It looks like an uphill battle to me.

Should we offer both options here, i.e., cycle through the tidyverse and the TS/Rust way?

@JosiahParry
Copy link

As a Rust programmer and an R programmer, I quite appreciate that codegrip formats function arguments to have the closing paren and leading { on their own line. The unbalanced closing of the tidyverse style guide feels....unbalanced. It would be great to have the default be balance and opt-in to the tidyverse style guide.

@jrosell
Copy link

jrosell commented Oct 17, 2024

Single-indent is now included as an option in the Tidyverse style guide

https://style.tidyverse.org/functions.html#multi-line-function-definitions

3.3 Multi-line function definitions

There are two options if the function name and definition can’t fit on a single line. In both cases, each argument goes on its own line; the difference is how deep you indent it and where you put ) and {:

    Single-indent: indent the argument name with a single indent (i.e. two spaces). The trailing ) and leading { go on a new line.

    # Good
    long_function_name <- function(
      a = "a long argument",
      b = "another argument",
      c = "another long argument"
    ) {
      # As usual code is indented by two spaces.
    }
    Hanging-indent: indent the argument name to match the opening ( of function. The trailing ) and leading { go on the same line as the last argument.

# Good
long_function_name <- function(a = "a long argument",
                               b = "another argument",
                               c = "another long argument") {
  # As usual code is indented by two spaces.
}

These styles are designed to clearly separate the function definition from its body.

# Bad
long_function_name <- function(a = "a long argument",
  b = "another argument",
  c = "another long argument") {
  # Here it's hard to spot where the definition ends and the
  # code begins, and to see all three function arguments
}

If a function argument can’t fit on a single line, this is a sign you should rework the argument to keep it [short and sweet](https://design.tidyverse.org/defaults-short-and-sweet.html).

I prefer Single-indent to Hanging-indent and I know I'm not alone on this.

@krlmlr
Copy link
Author

krlmlr commented Oct 17, 2024

The current version of codegrip cycles between one line, single indent, and hanging indent on my machine. Can you confirm?

@krlmlr krlmlr closed this Oct 17, 2024
@jrosell
Copy link

jrosell commented Oct 22, 2024

I can confirm current codegrip permits single-indent. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants