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 & whitespace #83

Merged
merged 4 commits into from
Jul 28, 2023
Merged

Conversation

jameshcorbett
Copy link
Member

No description provided.

@garlick
Copy link
Member

garlick commented Jul 27, 2023

This is a good idea IMHO!

However to get closer to project norms for C code you might want to pull in the latest attempt at a clang-format by @trws from flux-framework/flux-core#4694.

@trws
Copy link
Member

trws commented Jul 27, 2023

Oh yeah... we should finish fixing that up. It was pretty close IIRC.

@jameshcorbett
Copy link
Member Author

Should I hold off on this PR while we iron out clang-format or should I move ahead with it?

@trws
Copy link
Member

trws commented Jul 27, 2023

TBH, I'd probably say go for it, we can always rerun later. Might be good to configure these commits to be ignored by blame commits in git though so they don't hide everything. Example here if you haven't done the .git-blame-ignore-revs thing before: https://akrabat.com/ignoring-revisions-with-git-blame/

@jameshcorbett
Copy link
Member Author

OK done, although I noticed clang-format left some unreasonably long lines unchanged...

@trws
Copy link
Member

trws commented Jul 27, 2023

Lines over 88 chars should only persist unbroken if there's nothing to break. Is there somewhere it's doing something strange?

@jameshcorbett
Copy link
Member Author

No actually, upon further investigation there was one line that it left over 88 characters for some reason, and there were a few that I thought were 89 characters but were actually 88. All the changes are reasonable enough I think.

@garlick
Copy link
Member

garlick commented Jul 27, 2023

We normally break lines in C at 80 characters.

@trws
Copy link
Member

trws commented Jul 27, 2023

We had that discussion before, probably in slack since it doesn't seem to be in the issue/PR history, when we were setting up black as the python formatter and I was working on clang-format the last time. The number of spurious linebreaks drops significantly if there's a little bit of slop space above 80, for black they chose 88, and at the time IIRC we had general agreement to adjust that, so that's what I had put in the clang-format as well.

@garlick
Copy link
Member

garlick commented Jul 27, 2023

Ah OK sorry! That's fine then I guess.

@jameshcorbett
Copy link
Member Author

Whoops I had just adjusted it down to 80, will fix...

|| !(hlist = hostlist_from_array (nodelist))) {
|| !(hlist =
hostlist_from_array (nodelist))) {
Copy link
Member

Choose a reason for hiding this comment

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

Compound conditional line breaks are usually done like the original in our code base. Is that fixable?

Copy link
Member

Choose a reason for hiding this comment

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

Ok that's odd... I would have expected it to keep it the original way here because it's not an argument. There are other spots in this file where they got indented because there's nesting, but I'm not sure why this is happening. Will check it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

This particular example probably no longer applies now that I brought the limit back to 88

Copy link
Member

Choose a reason for hiding this comment

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

@jameshcorbett, what version of clang-format are you using? With these settings, and clang-format 16, I get this:

    if (flux_kvs_lookup_get_unpack (fut,
                                    "{s:{s:o}}",
                                    "execution",
                                    "nodelist",
                                    &nodelist)
            < 0
        || !(hlist = hostlist_from_array (nodelist))) {
        flux_log_error (h,
                        PLUGIN_NAME
                        ": "
                        "Error fetching R from shell-counting future");
        prolog_status = 1;
        goto cleanup;
    }

(note that this is without the wrapper I'm working on in the other PR to fix the dangling < 0 in the middle)

Copy link
Member Author

Choose a reason for hiding this comment

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

12.0.1

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm updating it now...

Copy link
Member

Choose a reason for hiding this comment

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

Good idea, technically 11/12 support everything in the config, but I think it was 13 that fixed a bunch of alignment issues when some of the options we use are combined.

@trws
Copy link
Member

trws commented Jul 27, 2023

Do whichever you prefer for now @jameshcorbett, we'll hopefully hash out the last few bits in the PR over on core and probably have an update, but I don't see that as a reason not to use the tooling in here in the meantime. I want to avoid stalling you on that since we've been working on it, on and off, since 2015... hmm... what's the emoji for simultaneous laughing and crying? 😭 🤣 ?

@jameshcorbett jameshcorbett force-pushed the style-whitespace branch 2 times, most recently from 2ed8736 to 7ef7056 Compare July 27, 2023 21:14
@jameshcorbett
Copy link
Member Author

Ok, sorry for changes, I brought the line length back to 88 since that's my preference.

@jameshcorbett
Copy link
Member Author

One more push to update the clang-format used to version 16.

@jameshcorbett
Copy link
Member Author

@garlick @trws OK to set MWP?

@trws
Copy link
Member

trws commented Jul 27, 2023

Oddly, this seems to still have the alignment issue, I would have thought that would take care of it. it looks like the issue is from treating the _pack and _unpack functions as whitespace-sensitive. It's adjusting the indent of following || lines inward for some reason. For this project, since it doesn't use the "pair-per-line" jansson convention with those, removing the WhitespaceSensitiveMacros block from the config is probably a good idea. That should take care of it. Makes me wonder why I haven't seen that in the flux-core test though.

Problem: coral2_dws.py has some lines that are too long.

Run the 'black' formatter over it.
Problem: C style should be standardized. Some
developers rely on an automatic tool to do
their formatting.

Add a .clang-format file for clang.
Problem: the style in all of this repo's C files
is messy and irregular.

Run clang-format over every file.
Problem: commits that make style changes will confuse
git blame.

Add a file for telling git to ignore those commits
when assigning blame.

git can be configured to always use this file with
'git config blame.ignoreRevsFile .git-blame-ignore-revs'
@trws
Copy link
Member

trws commented Jul 27, 2023

That got the indents, it looks like it didn't show up in core because it's really, really rare to have pack/unpack in single if chains for whatever reason there. I'm good here pending others's approval.

@grondo
Copy link
Contributor

grondo commented Jul 27, 2023

The number of spurious linebreaks drops significantly if there's a little bit of slop space above 80, for black they chose 88, and at the time IIRC we had general agreement to adjust that, so that's what I had put in the clang-format as well.

For Python that is fine, but I do find myself lengthening shortening variable names to play the "how to get black to format this more reasonably" with 88 character limit. I wonder if we'll want to shorten it for flux-core at least. We have codified 80 character limit in RFC 7.

@trws
Copy link
Member

trws commented Jul 27, 2023

Sure, not planning to argue that here so much as point out that's what's in the file James was pointed to. Could always do what the black, and spack actually, folks did and do our own test to determine where the dog-leg is between reducing extra lines and keeping things tight.

@jameshcorbett
Copy link
Member Author

@garlick if you'll stamp this with your approval I'll go ahead and set MWP

Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

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

OK I don't think these rules are ready for flux-core where there's a lot of established code purposefully formatted a certain way, but it does fix quite a lot here so LGTM.

@jameshcorbett
Copy link
Member Author

Thanks!

@mergify mergify bot merged commit a543de9 into flux-framework:master Jul 28, 2023
8 checks passed
@jameshcorbett jameshcorbett deleted the style-whitespace branch July 28, 2023 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants