-
-
Notifications
You must be signed in to change notification settings - Fork 401
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] Maximum line length #1785
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1785 +/- ##
===========================================
+ Coverage 69.57% 83.18% +13.61%
===========================================
Files 30 41 +11
Lines 3957 6270 +2313
===========================================
+ Hits 2753 5216 +2463
+ Misses 1204 1054 -150
Continue to review full report at Codecov.
|
IMO harder to read and archaic given modern code viewers and editors (wrapping), |
docs/src/style.md
Outdated
|
||
#### TODO: Line breaks | ||
Following the Google style guide for [line length](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#32-line-length) | ||
in python, keep lines under an 80 character limit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a contentious point so we need to give our own motivation and not just defer to the google style guide.
My thinking is that for consistency, we need some guideline on line length. 80 characters is a reasonable pre-existing convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we just make this a recommendation. What about:
Our foremost goal is to maximize code readability. Very long line lengths are hard to read since they either require horizontal scrolling, or are wrapped uncontrollably by a text editor. Thus, where possible, keep line lengths under 80 characters (an arbitrary, but pre-existing convention). We make an exception for lines in which manually breaking the line over multiple lines is worse for readability.
Examples include
- URLs
- path names
- long string constants not containing whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"wrapped uncontrollably by a text editor" is pretty unconvincing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, please just make it a recommendation. I don't plan to start enforcing line lengths in any packages I author. though for packages that aren't mine, I will follow the surrounding style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlubin it is also "consistent" to not have line limits at all
Maybe we should consider that we use verbose names for everything. We also have many parametric types. And 4 spaces tabs... |
@joaquimg makes a great point I hadn't even thought of. though I prefer no line limit, I would be OK with a "target/soft maximum line length" of n characters (n = 120 maybe?). if the limit is arbitrary anyway, we may as well be a little soft about it. then n chars is a goal, and clearly a line of 1.5*n chars is too long and should in good conscience be broken up. guidelines like "verbose variable names" require judgment and subjectivity, so why not line lengths too? the code is littered with ugliness like https://github.com/JuliaOpt/MathOptInterface.jl/blob/f4db9518c49a85b70f72043f01a2bce93d44d981/src/Test/contlinear.jl#L1482 where with a target line length of 80 chars we would be allowed to just keep it on the same line of ~85 chars. |
i want to avoid feeling as though the style guide is too totalitarian. it's not cute. i see no reason to perpetuate old python style doctrines. finally, i will make another plug for recommending semantic line breaking for long comments and print messages (and the same idea can be applied when breaking up long lines of code into coherent chunks). |
Even on modern screens, it still makes sense to use 80 characters because we might split our screen to edit multiple files at the same time and 80 characters is better for readability.
By the way, for this reason, this is the Python limit recorded by wikipedia |
obj = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2.0, 1.0], [x, y]),
0.0) True, that's not very nice. A better way (to my eyes) is: obj = MOI.ScalarAffineFunction(
MOI.ScalarAffineTerm.([2.0, 1.0], [x, y]),
0.0) Breaking things up into smaller lines makes each statement easier to read. Consider: obj = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2.0, 1.0], [x, y]), 0.0)
obj = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2.0, 1.0], [x, y], 0.0)) |
@chriscoey the reference on semantic line breaks is specifically for text. What do semantic line breaks mean for code? |
agreed with @odow, that looks nicer. so why don't we recommend how to break up lines, so that this outcome results? in particular, 4 spaces indenting only. all throughout the code we have things like:
whereas it would be more consistent to use 4 spaces indenting and write
I'm fine with soft line length limits if it is accompanied by consistent indenting practices. though i agree with @joaquimg and think 80 chars is too small given that variable and function names etc have to be verbose now. |
That's a good point. We don't do this consistently now. I would look to a few code autoformatting tools autopep8, gofmt, and clang-format for how they align function calls and other lists of things that overflow a line. |
Recommendations on how to break lines would be great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been putting off looking at this because I don't enjoy debating about line lengths, but the suggestions are pretty reasonable. If we cite an existing autoformatter for people to experiment with if they're unsure then I think we're covered.
Okay, I've removed the contentious points. I'm in favour of merging this so we can move past the discussion. |
@chriscoey Your major objection of not having providing guidelines for how to break a line is now mostly addressed. https://yapf.now.sh/ seems to provide a reasonable point of reference to the extent that julia syntax overlaps with python syntax. What do you think? |
Looks good. |
looks good. aside: would be nice to have a Julia version of YAPF |
Merged. Anyone wanting to re-ignite the debate can make a new PR. |
This one is going to be contentious (looking at @chriscoey).
Ref issue: #1780
Ref previous PR: #1781