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

Style all code samples #125

Open
wants to merge 6 commits into
base: source
Choose a base branch
from
Open

Style all code samples #125

wants to merge 6 commits into from

Conversation

khwilson
Copy link
Contributor

@khwilson khwilson commented May 6, 2021

In the spirit of #123, I think we should also encourage code to be styled similarly (so it's easier to compare examples across all of LOST).

This PR adds a styler for R and Python code. It uses black for Python and styler for R. It also proceeds to style all the code.

Notably, these stylers are pretty opinionated, so before committing, it would be good to make sure that this is the set of rules that people are comfortable with. In particular, in R, some controversial rules are:

  • Uses <- instead of =
  • Double quotes instead of single quotes ("thing" not 'thing')
  • Spaces around =
  • block options like:
df <- tibble(
  ~x,
  ~y,
  1,
  2
)

not

df <- tibble(~x, ~y,
             1, 2)

@grantmcdermott
Copy link
Contributor

grantmcdermott commented May 6, 2021

I try not to be too dogmatic about it, but I'm squarely in camp = for assignment in R nowadays, rather than <-. One of my major reasons is that it just makes it easier for switching between languages by removing a small, but unnecessary syntax hurdle.

Given LOST's primary goal is to encourage said language switching and multilingualism, I'm prepared to advocate for =.

Rest looks good... maybe with the exception of the blockquotes styling. I like to group like with like and so the second option seems far more natural to me.

@NickCH-K
Copy link
Contributor

NickCH-K commented May 6, 2021

Heh, I'm squarely in <- camp since it clarifies the whole assignment concept. But I see your point for easy language switching

@khwilson
Copy link
Contributor Author

khwilson commented May 6, 2021

Hah! I figured this PR might be slightly more controversial than the tests ;-)

@grantmcdermott
Copy link
Contributor

grantmcdermott commented May 6, 2021

@NickCH-K Calling in some R heavy hitters to back me up here, here, and here ;-)

(K, easy to find countervailing views but I personally find these arguments compelling alongside my own teaching experiences. Most annoyingly, I recall someone linking to Ross Ihaka himself expressing regret about the arrow assignment — other languages seem to be doing fine and he apparently prefers = too — but I can't find it now.... honest!)

UPDATE: Found it! https://youtu.be/88TftllIjaY?t=2100 (the whole talk is great btw; I think you two will both enjoy it.)

@aeturrell
Copy link
Contributor

I'm not an R expert (by any means!), but my understanding was that both the Google and tidyverse R styles prefer arrows. Is there an argument for following these styles, especially when most people coming to LOST are likely to have come via the tidyverse suite of packages? (Anecdotally, tidyverse seems by far the most popular route into the R ecosystem.)

@khwilson
Copy link
Contributor Author

khwilson commented May 7, 2021

fwiw, styler is the tidyverse styler. You can change the settings, these are just the defaults. I tend to be a sheep when it comes to styling, and so my opinion is what Arthur said. However, as a non-R person here, I hold this opinion very loosely.

@aeturrell I assume as the other Pythonista here you have no objections to black? I am definitely annoyed by some of their choices (why do binary operators go at the beginning of lines 😱 ) but the whole ecosystem has clustered around it so it seems appropriate?

@aeturrell
Copy link
Contributor

@khwilson: black certainly has its quirks but it's a good default and, as you say, widely used/recognised, so yes, I think it's a solid choice here.

@lgreski
Copy link

lgreski commented Jul 19, 2022

<- is preferred over = in R for at least two reasons. First it is consistent with <<- the assignment operator to assign an object to the parent environment. Second, = has restrictions on its use, such as being leftward only (in contrast, -> works just like <- as in 15 -> x). See also Forms of the Assignment Operator in R.

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.

5 participants