Warning. Blather follows.
Swift protocols describe the surface that connect a feature provider API with its consumer. Protocols establish a communication contract. They ensure a fit between each required member and the provider’s implementation. It’s like whether a virus can attach to a host cell’s receptors, or whatever the actual biological equivalent is.
You describe protocols using nouns (typically ending in Type, e.g. MirrorPathType, MutableCollectionType, ErrorType) and adjectives (typically ending in ble, like Streamable, Strideable, _ColorLiteralConvertible) that discuss what a conforming type is and what it does.
When naming a protocol, you’re of course not limited to Type and ble endings. Your protocol can be, for example, a DataProvider or a FloatConsumer. A protocol can describe a delegate relationship DownloadProcessingDelegate or a data source ListViewDataSource. You may implement an OutputDestination or an IntegerSink.
With ble endings, however, comes a world of pain because English basically sucks when it comes to whether to use able or ible. So I thought I’d share some basic rules I’ve scraped up from the net to help name protocols:
- Most of the time, you want able and not ible. The Spelling Blog suggests that there’s a 5:1 chance of able being right compared to ible.
- If the main part of the protocol name is a complete English word, even if you’re going to drop an e or y at the end you probably use able. For example “Streamable“, “Strideable“, “_ObjectiveCBridgeable“, “Reflectable“. Access/accessible and collapse/collapsible are notable exceptions.
- If the word before the ending is not strictly English, e.g. permissible’s permiss and audible’s aud, you’re probably going to use ible.
- According to the Oxford Dictionaries site, if a word ends with a hard c or g, it’s able, for example UserNavigable.
- If you can construct a word with the root word and ation, use able. If you can use ition, sion, cian, or ion, use ible. For example, a vis root is like vision, so the protocol name would be MemberContentVisible. Convert goes to conversion, so I presume that’s why it’s convertible.
- The Spelling blog says any Latin-sourced -are infinitive maps to able, while -ire and -ere are ible. The write-up adds that any new techno-word is able such as biodegradable, emailable, clickable, etc.
Now that I’ve wasted your time with all those points, I’d like to mention that all the words you want to use in a protocol are likely available in the OS X dictionary, so you can just look them up. A quick spell check1 will help you avoid unflattering code smell.
1 Now that I mentioned spell check, Skitt’s Law mandates that I majorly messed up somewhere in the post on spelling.
Update: k asks “Is there a reference for why protocols should be named like that? I forget if Apple recommended it or if that was community driven” Answer: personal mandate. Manifold2 destiny.
2 Please tell me that someone gets this joke
Comments are closed.