Skip to content

Style: removing unnecessary usages of \ from the codebase #11954

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

Closed
wesm opened this issue Jan 4, 2016 · 7 comments
Closed

Style: removing unnecessary usages of \ from the codebase #11954

wesm opened this issue Jan 4, 2016 · 7 comments
Labels
Code Style Code style, linting, code_checks good first issue

Comments

@wesm
Copy link
Member

wesm commented Jan 4, 2016

I've found that using parentheses (which allow for automatic continuation) instead of \ results in a lot more readable code. The lone exception is using \ with long strings and avoiding a line break at the start of the string.

Worse:

return GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD and LET and THE and HATE and FLOW\
    and THROUGH and YOU

Better:

return (GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD and LET and THE and HATE and FLOW
        and THROUGH and YOU)

OK:

return """\
GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD and LET and THE and HATE and FLOW
and THROUGH and YOU"""
@wesm wesm changed the title Style: removing unnecessary usages of \ from the codebsae Style: removing unnecessary usages of \ from the codebase Jan 4, 2016
@jorisvandenbossche
Copy link
Member

xref #11951 (comment)

@jorisvandenbossche jorisvandenbossche added the Code Style Code style, linting, code_checks label Jan 4, 2016
@rockg
Copy link
Contributor

rockg commented Jan 4, 2016

Part of the underlying issue here is some editors nowadays (e.g., pycharm) have automatic behavior when it comes to continuation and uses '' continuation by default.

@wesm
Copy link
Member Author

wesm commented Jan 4, 2016

Can that be disabled?

@rockg
Copy link
Contributor

rockg commented Jan 5, 2016

There's an automatic wrap option that will wrap lines automatically with '' but if the statement was started with '(' then it will wrap without ''. If one does not wrap automatically then the syntax is up to the user. If a portion of the statement is moved to the next line then '' is used if not already wrapped in '()'. There is no way to add '()' to these statements by default but this should probably be an editor option. PyDev has no such behavior and relies on the user putting in the appropriate continuation and I'm unsure of other editors.

@rockg
Copy link
Contributor

rockg commented Jan 5, 2016

So, I think if people get in the habit of using '()' at the outset the editor continuation won't be an issue.

@jbrockmendel
Copy link
Member

@jorisvandenbossche does black take care of this for us?

@jorisvandenbossche
Copy link
Member

For cases in python code, yes. So I think we can close this.
There are some cases in docstrings where we still need it (but that's not the cases discussed above I think)

@jorisvandenbossche jorisvandenbossche added this to the No action milestone Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks good first issue
Projects
None yet
Development

No branches or pull requests

5 participants