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

src: update cppline limit to 100 #45033

Closed

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Oct 16, 2022

The existing 80 has become rather restrictive.

@jasnell jasnell mentioned this pull request Oct 16, 2022
@Trott
Copy link
Member

Trott commented Oct 16, 2022

@nodejs/cpp-reviewers

Copy link
Contributor

@RaisinTen RaisinTen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

ColumnLimit: 80
also needs to be updated to 100 now.

@bnoordhuis
Copy link
Member

bnoordhuis commented Oct 17, 2022

It's deliberately restrictive, always has been. It forces you to write more succinct code.

Longer line lengths optimize for writability, shorter line lengths for readability. Code is read more often than it is written.

@tniessen
Copy link
Member

My main concern right now is the format-cpp task. I've had to update PRs countless times because format-cpp wanted me to rewrite surrounding, existing code to match its code style. At least, once code has been committed, it won't have formatting issues. Now I am wondering if changing this rule will negatively impact progress there.

Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell jasnell force-pushed the update-cpplint-line-limit-to-100 branch from 96975d9 to 4822b44 Compare October 17, 2022 17:01
@jasnell
Copy link
Member Author

jasnell commented Oct 17, 2022

At least, once code has been committed, it won't have formatting issues. Now I am wondering if changing this rule will negatively impact progress there.

I'm not convinced it would be an issue. At least, so far the experience with the quic pr has been pretty painless with this. I'd suggest we could go with this as an experiment. Rolling it back would be fairly straightforward if necessary.

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mulled this over but I really don't like flowery prose - you know the kind, interminable run-on sentences that take up half a page - and the same goes for code. Hemingway > *

@jasnell jasnell added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Oct 18, 2022
@jasnell
Copy link
Member Author

jasnell commented Oct 18, 2022

Added tsc-agenda for discussion. If there are technical reasons not to make the change, that's one thing, but the objections raised so far appear purely subjective. @tniessen raised a possible technical issue that bears consideration.

@MoLow
Copy link
Member

MoLow commented Oct 18, 2022

just for the sake of discussion, I disagree with

Shorter line lengths optimize for readability.

in many occasions reading the beginning of a line can spare you from reading the entire line.
breaking a line of code into multiple lines force your eyes to read what could have been mentaly part of a shorter line.

for example, SomeClass::SomeMethod(with, a, list, of, arguements); is more readable than

SomeClass::SomeMethod(with, 
                      a, 
                      list, 
                      of, 
                      arguements);

especially when SomeClass::SomeMethod is named in a good and descriptive name

@jasnell
Copy link
Member Author

jasnell commented Oct 18, 2022

Case in point, in the quic PR, I had to shorten...

  int err = nghttp3_conn_add_write_offset(connection_.get(), stream_data->id, datalen);

to

  int err = nghttp3_conn_add_write_offset(connection_.get(),
                                          stream_data->id,
                                          datalen);

I find the shorter lengths far less readable than the longer alternate.

@cjihrig
Copy link
Contributor

cjihrig commented Oct 18, 2022

I find the shorter lengths far less readable than the longer alternate.

Looking at it in isolation in the GitHub UI, the single line is more readable. As someone who exclusively works on a small screen and frequently looks at git diffs in my terminal, I disagree that it's more readable while I'm trying to do actual work though.

@Trott
Copy link
Member

Trott commented Oct 18, 2022

just for the sake of discussion, I disagree with

Shorter line lengths optimize for readability.

I dislike restricting the line length to 80 characters in general, but nonetheless the research that has been done bears out what Ben said: Keeping the lines to 80 chars or less improves readability.

Granted, almost everyone who cites the research cites (I think) a single study (but multiple papers) by Buse & Weimer. So you might argue that the data on this topic is thin. You might also argue that a study done in 2008 may not reflect the reality of modern code bases. You might also argue that maintainability is different (albeit related) to readability and this improves maintainability because (for example) we don't have to reformat lines copied/rebased/cherry-picked/whatever from other code bases. And so on.

But for Ben's point, what data there is backs up Ben on this as far as I am aware. Keeping most lines shorter than 80 characters correlates strongly with code readability (although there were some other elements that correlated more strongly in Buse & Weimer's research). And I say that as someone who dislikes 80 character line length limits. (100 or 120 seems reasonable to me.)

@GeoffreyBooth
Copy link
Member

We went through this whole debate for JavaScript in #41509 and #41586. I think the C++ rule should just match the JS one, where we settled on 120 characters (for now).

I would also support upping the limit on Markdown either to match or for Markdown to have no limit.

@bnoordhuis
Copy link
Member

the objections raised so far appear purely subjective

I mean, of course - the compiler doesn't care about line length but I, as someone who reviews a lot of code, definitely do.

W.r.t. #45033 (comment)

I find the shorter lengths far less readable than the longer alternate.

For me it's completely the other way around. My eyes just kind of start to glaze over 2/3rds in.

@tniessen
Copy link
Member

@tniessen raised a possible technical issue that bears consideration.

@jasnell Just to clarify my (possibly unfounded) concern: C++ PRs have often been much larger than necessary recently to pacify format-cpp, which requires surrounding lines to be formatted properly. That means that a one line diff can turn into reformatting an entire function. (Because make format-cpp does not work nicely in some git workflows, I tend to postpone it and then have to update the PR just to pacify format-cpp.) I am wondering if this change would cause more such unnecessarily large diffs because clang-format might want to unwrap lines that fit into the new limit but not into the old.

@jasnell
Copy link
Member Author

jasnell commented Oct 19, 2022

@tniessen ... ah, yeah, that's a good point. I had no intention of making it so that existing code would need to change but adjusting the formatter would absolutely have that impact... and for that reason alone I'll withdraw this.

@jasnell jasnell closed this Oct 19, 2022
@tniessen
Copy link
Member

(On the other hand, if this is something that we'd want to do eventually, I don't know if waiting is going to give us any benefit.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tsc-agenda Issues and PRs to discuss during the meetings of the TSC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants