-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
C++domain: Idiomatic spacing of ptr-operator and ref-qualifier #7491
Comments
It is indeed a bold statement which I (perhaps not surprisingly) do not agree with :-). This is perhaps a semi-religious issue like east-vs-west const, so I fully agree that it should be up to the user to decide.
I consider this practically impossible to implement.
Sounds good to me, though the option should have a less contentious name :-). From a technical perspective the current spacing is grammar-centric (the declarators (e.g., * and &) are grouped with the declarator-name), while the other style groups the declarators with the decalration-specifiers. How about the slightly long-winded
As I object to "idiomatic" I am definitely against this :-).
As mentioned, the current style is based on how the C and C++ grammars are written, though in all fairness, biased towards my personal formatting opinion in more complicated cases involving parameter packs. I don't mind implementing option 2 at some point, but what would very helpful would be a set of test cases, with the result in both styles. The more complicated issues comes with multiple qualified pointers, parameters packs, and differentiation of whether there is a declarator-name or not (e.g., function declarations without parameter names). |
First of all, thank you very much for your comments and your appreciation of my request. I certainly do not want to rage any pseudo-religious wars. But I am also convinced that the issue is not of the same character as east-const vs. west-const. I would be curious to learn about the cases involving parameter packs or other cases you are having in mind where this style may be of advantage. I could also be interesting to collect more opinions about this, maybe a poll among users? Of course I could live with option 2 (and I do not insist on a particular name). I am just afraid that all the effort of implementing and maintaining it will be futile since hardly anyone would be using one of the two styles 😉. |
I decided to cut my teeth on Sphinx, and I like having this option, so I opened PR #7507 that allows customization of the placement of the ptr/ref token via |
@vector-of-bool, thanks for your work in #7504. A Single DeclaratorLeftI personally don't prefer this style so there are a few cases where it's not clear to me what spacing people use. Do you agree with the table?
Right (current Sphinx)While this is my preferred style, it looks like some of the cases are not rendered as I usually write code.
Combinations of DeclaratorsNote all of these seem to be trivial extensions of the single-declarator cases. I have a few example tables for the "right" style, but we should probably agree on the single-declarator cases first. Other Wonderings
|
About your table LeftIn all rows with (?) the const refers to the variable being declared, i.e.
In the unnamed case, just leave out the name and its preceding space. There are more cases involving cv-qualification: The object pointed to can be const/volatile, the member function can be cv-qualified. All of these should not be affected by the question on how to place the Another thing of interest for this discussion is the placement for member function ref qualifiers.
About your table RightAgain, I would add a space between the const (which refers to the variable) and the type, only now the
This would be totally in line with A function returning a reference is currently rendered by Sphinx as
Thus I think that the unnamed reference cases in your table should be
For ref-qualified member functions in the right style I suggest:
(1) I agree. What is the current behaviour in the template declaration?
or
About your other wonderings
|
Problem
When declaring objects (e,g, types, members, functions) in the cpp domain, sphinx accepts
arbitrary spacing between types, cv-qualifiers and ref-qualifiers. It then produces output
in a consistent way (which is a plus) but which cannot be influenced by the user (which is a problem).
For example
leads to output
The problem here is that the spacing chosen by sphinx is not the idiomatic way used by the C++ community (I am aware that this is a bold statement, but https://en.cppreference.com and https://github.com/cplusplus/draft are good support for this.)
An idiomatic spacing for the example above should look somewhat like
This is important, since IMO documentation should look like the code we write and it should follow conventions which are common in the specific language.
Supporting this kind of spacing could lead more C++ developers to consider using sphinx for documentation.
Possible solutions
cpp_idiomatic_spacing
is added which produces the desired output. The default leaves the output as is.Option 1
This probably requires huge changes to the output generating functions in
cpp.py
.It would make the output depend entirely on the user input. This can be seen as an advantage (full control for the user), but also as a disadvantage (potential for inconsistent output).
Option 2
Feasible, but would lead to lots of branching and duplication in the code and the tests.
The question is whether someone would still want the default behavior once the option is available and if the effort maintaining two output variants is worth while.
Option 3
Implementable with relatively low effort.
Since the current choice of spacing by sphinx is somewhat arbitrary (or taken over from Python or C), a different spacing should be just as good. I am not sure, however, if this would still be considered a breaking change.
Suggested solution
I would appreciate feedback to the above suggestions.
Personally I favor option 3 and would be willing to contribute a PR.
The text was updated successfully, but these errors were encountered: