As part of the Haiku Format Bot work, I am monitoring the suggestions the bot makes. One recurring item is about how C-style casts are formatted. See change 7356 for example.
The question whether we want to C-style cast operators to be followed by a space, or not. Example:
// Examples with no space after the cast
WirelessNetworkMenuItem* aItem = (WirelessNetworkMenuItem*)a;
BMenuItem** begin = (BMenuItem**)fItems.Items();
// Examples with a space after the cast
WirelessNetworkMenuItem* aItem = (WirelessNetworkMenuItem*) a;
BMenuItem** begin = (BMenuItem**) fItems.Items();
Purely anecdotal, I feel like the style with no space is more common in our codebase.
Currently, our coding guidelines do not specify the expected style. They do mention that C-style casts are to be avoided, however, that does not really help decide the formatting if a C-style cast is accepted into the code base.
Per this poll, I would like to gauge the thinking of the community about this style issue, with the intention of codifying the result in the haiku-format tool.
Also, do we know who voted in these forum votes? They are not restricted to people with commit access, which is how we’ve done votes historically. Also on historical note: usually there is some discussion, and if all the devs agree, there’s no need for a vote.
So, yes, as far as I noticed there is no space after casts in the existing code? And I think we should keep it that way (no particular reason, just to avoid changing a lot of existing code and having to re-train myself).
To me it is similar to the other unary operators (++, --, !, ~, …), they have high operator precedence, so they get stuck together with the variable they are affecting, while lower precedence things get spaced out.
Thanks everyone for their contributions. I think based on the poll (which was indeed not intended as a vote), the existing code and the notes on here, the consensus seems to be to not have a space after a C-style cast. I will take the following next steps:
Yes. And using tabs for that. I think that it do not improve readability and maintaining table formatting is a waste of time. Method names and return types also often do not fit to column width making it even more messy.
Using tabs for table formatting makes formatting broken when tab size is not set to 4 spaces. Many code viewers including Haiku Gerrit when not logged in use 8 spaces per tab by default.