[webkit-dev] WebKit Objective-C++ style, pointer and reference placement

Kimmo Kinnunen kkinnunen at apple.com
Tue Dec 21 04:08:42 PST 2021


Currently we have this:

https://webkit.org/code-style-guidelines/#pointers-and-references <https://webkit.org/code-style-guidelines/#pointers-and-references>

Pointers and References
Pointer types in non-C++ code
Pointer types should be written with a space between the type and the * (so the * is adjacent to the following identifier if any).

This is not what was originally intended, and I’m planning to fix the document. 

The original idea was to say: “Objective-C classes should have space between the type name and the *”.

I can update the document to reflect this. However, this rule is a bit difficult to enforce and quite difficult to format automatically. Also, subjectively for me, it is a bit hard to remember. Maybe also for other people, as current Objective-C++ is formatted inconsistently in this regard.

To enforce this, I’d imagine we hardcode a semi-comprehensive list of Objective-C class names to check-webkit-style. For automatic formatting, the scripts can fix up clang-format diffs based on the hardcoded list.

An alternative suggestion would be to change the rule and document as follows:
 * All pointers, references and rvalue-references in Objective-C++ are formatted as current C++ style mandates
 * All C and Objective-C code should be formatted with rules consistent to the C++ rules
 * The exception would be public Objective-C headers and WebKit SPI headers, which would be formatted as part of Apple internal API definition process

The change above would be fitting to programmatic formatting and format verification, as it simplifies the rules and avoids the need of semantic analysis of the code for the formatting purposes.

Please reply to this to discuss which way would be preferable.

The bug:
https://bugs.webkit.org/show_bug.cgi?id=234294 <https://bugs.webkit.org/show_bug.cgi?id=234294>


Br,
Kimmo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20211221/ed9c9dc3/attachment.htm>


More information about the webkit-dev mailing list