-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Poor readability of preprocessor generated by Tools/clinic #125963
Comments
I think you should use a C formatter (aka pretty-printer) if you want to see the code formatted differently. But I'm not sure they'd format |
Probably, it's a good idea and simple to implement (c.f. manual code formatting in the Tools/clinic).
The |
PEP-7 doesn't specify what to do for processor macros, I think. It might be worth documenting it. FWIW, I like the current style though. |
Actually, what I'm trying to say is that the preprocessor directives should be aligned in the first column, not indented with the statements.
|
Which one? Sometimes there are no indentation for nested preprocessor directives, sometimes indentation with one space, sometimes two.
That too. This part seems to be consistent across hand-made files. |
Yes, that's what I want to say. The generated code is inconsistent with the style of manual writing, which is actually strange. And from my example, it's very simple. What if the situation is complicated? |
I think we should specify the style of the preprocessor in PEP7, which is really common. And it is difficult to read. If it is not strictly stipulated, it will greatly reduce the readability. For example
Bad
If the above example is complicated, how many spaces are needed? And how should it end? |
Honestly, PEP 7 probably needs to get some updates. There's plenty we don't specify, at least compared to PEP 8.
Aren't we already doing that in most code, and what clinic is doing already? |
In fact, the code generated by the clinic is not consistent with the code style written by humans, which I have given above. If my request is allowed, I would like to apply for PEP7 to add specifications on preprocessing style. Even if we cannot refactor the existing clinic-generated code on a large scale, we must stipulate the style of manual writing. |
Ah, I do see that clinic outputs that style. Generated code doesn't have a readability requirement though, so I would be hesitant to change things solely for that purpose. Regarding PEP 7 changes, I highly suggest going to DPO first, because nobody can agree on styles. I'm almost certain there are core devs who like indenting the preprocessor directives. |
For AC, I personally think we shouldn't strive for "readability". Heck, I'd even be in favor of having compressed files in AC just for the sake of minimizing the repository size but AC has other issues that are more pressing IMO. If we were to make it PEP-7 compliant, we'll have a very huge diff which I think is not worth since it could create conflicts on existing PRs (and probably many people will need to re-run AC with a forced flag or just remove all clinic files). |
I'm not referring to the files generated by the clinic, but the overall style of the code base.
I noticed this problem a long time ago. In fact, the indentation of preprocessing in many places is not uniform. Edit: |
If you want to specify a macro guide for new code, you should open a DPO and follow PEP-I-don't-remember-the-number to update PEP-7 (there should be a core dev + SC vote IIRC or something like that). I think new pre-processing directives are usually following the file style or author's common sense. Now, if you are not referring to AC-files, then this issue should be closed (or the title should be changed and labels should be updated). In general, if I have nested #if defined(X)
# if defined(Y)
# endif
#endif I also put |
This issue is mainly about clinic. Actually, I just question whether the generated code should be consistent with the manual code.
In fact, the code you gave is different from the style in the repository. On the first layer of preprocessing it should only add one space, but you are adding two. It should be like this
Edit: |
If it's about clinic, then my stance is: we don't change the style. You are contradicting yourself with "I'm not referring to the files generated by the clinic, but the overall style of the code base.".
Not really. There are only 16 occurrences of |
There seems to be a misunderstanding. The style I refer to includes both clinic and human-written styles. But leaving human-written styles aside, the clinic-generated codes given above make it confusing for users who try to read them. like this
Edit: |
The immanent property of any auto-generated code is that sometimes people read one. E.g. to debug things.
There are reasons to include such auto-generated code in the repository history. Obvious one is written right above;) But I would speculate, that with using some indent-like autoformatter - clinic output will be more predictable.
That's a good point, but I'm not sure if this is so severe issue. Conflicts for autogenerated files are easy to fix. Just regenerate them.
I think this is still about AC. But to address that issue - PEP 7 should be updated first. PS: for workflow, see e.g. python/peps#3516. I don't think we should bother SC;) |
Yes, the user may not notice the existence of a preprocessor during debugging due to the same indentation. |
Proposal:
# Add a code block here, if required
from #125958
The indentation of the preprocessor generated by clinic seems strange, it puts the preprocessor and normal statements in the same column. This makes it less readable, even if it is generated, which can maintain correctness, but it does not exclude that no developer will read the code.
for example:
cpython/Modules/_posixsubprocess.c
Lines 569 to 580 in 75401fe
This is easy to understand for indentation.
The following clinic generated code:
Forgive me for not seeing the preprocessor at first glance. If it was not designed with reading in mind, I will close this PR.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
The text was updated successfully, but these errors were encountered: