[webkit-dev] WebKit Style: Whitespace for Objective-C protocols

Myles Maxfield mmaxfield at apple.com
Mon Feb 21 13:19:01 PST 2022


Hello!

I was working on a patch recently where I wanted to give an Objective-C variable a type of “id that conforms to protocol Foo.”

Should this be spelled like this:

id <Foo> myVariable

Or like this:

id<Foo> myVariable

I don’t see anything about this in the WebKit style guide <https://webkit.org/code-style-guidelines/>.

The former appears in WebCore, WebKit, and WebKitLegacy 1035 times, whereas the latter appears only 281 times. On the other hand, Apple’s documentation <https://developer.apple.com/documentation/metal/1433401-mtlcreatesystemdefaultdevice?language=objc> seems to prefer the latter.

Another consideration - This question is only about Objective-C protocols, not Objective-C generics. We already have a longstanding practice of spelling generics without the space, e.g. NSArray<NSString *> *. So, we could either intentionally choose for protocols to look visually similar to generics, or alternatively we could intentionally choose for protocols to look visually distinct to generics. Consider seeing something like Foo<Bar <Baz> *> *. Would the inconsistent spacing annoying you? Or would the spacing help you understand that Baz is a protocol but Bar is supplied as a generic type? Maybe the * characters already make that clear?

What should the style guide say here?

Thanks,
Myles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20220221/4e1bd15f/attachment.htm>


More information about the webkit-dev mailing list