The longest names in Cocoa
Ever since I started coding in Cocoa, I’ve been wondering what might be the longest name used for any function or constant in the entire API. Cocoa names can get quite long in general, so the longest one should be really ridiculously long… Of course I couldn’t leave it like this and I had to find out what it was :)
I ran a search for *.h files on the whole disk, and I determined that the interesting stuff was either in /Developer or in /System/Library/Frameworks, so I limited the search to these directories only. I passed the list of all header files through a Ruby script that looked for the really long ones and sorted them by length, and then I analyzed the results to find the winners (I decided to divide them into a few categories).
So here’s what I’ve found:
The longest name in the whole result set
cairo_atsui_font_
(104)face_ create_ for_ atsu_ font_ id_ REPLACED_BY_ cairo_ quartz_ font_ face_ create_ for_ atsu_font_id
This monstrosity was found in cairo-deprecated.h in X11 headers directory. Doesn’t really count as Cocoa though, it wasn’t even written by Apple (it says RedHat in the comments).
The longest names in Apple’s frameworks:
kBluetoothAMPManager
(88)Create Physical Link Response AMP Disconnected Physical Link RequestReceived kBluetoothHCIExtended
(84)Inquiry Response Data Type128Bit Service Class UUIDs With MoreAvailable
These were both found inside IOBluetooth.framework. Note to self: don’t try to code anything Bluetooth-related in Cocoa…
Popularity award:
__AVAILABLE_MAC_OS_X_
(83)VERSION_10_0_AND_LATER_ BUT_ DEPRECATED_ IN_ MAC_OS_X_VERSION_10_5
This award goes to this interesting macro and all its relatives, of which there are many (basically all possible combinations of existing MacOSX versions). These things are just *everywhere*… For the rest of the categories I’m going to ignore these, to make the results more interesting.
The longest names in Cocoa:
It’s hard to tell what exactly counts as Cocoa and what doesn’t, I’ve always thought of Cocoa as a broad term including all of Apple’s MacOSX frameworks. However, if you import <Cocoa/Cocoa.h>
in your code, it only includes Foundation, AppKit and CoreData, so I guess technically only these three form the core Cocoa framework.
Here are the winners in this category:
NSAccessibility
(62)Layout Point For Screen Point Parameterized Attribute NSAccessibility
(62)Screen Point For Layout Point Parameterized Attribute NSAttributed
(61)String Enumeration Longest Effective Range NotRequired
The first two are from NSAccessibility (AppKit), the third one from NSAttributedString (Foundation).
The longest names in UIKit:
delegateTitle
(57)For Delete Confirmation Button For Row At IndexPath
This one is defined in the header for UITableView, but it doesn’t appear in any official documentation, so it probably shouldn’t count.
willAnimate
(55)Second Half Of Rotation From InterfaceOrientation UIApplication
(55)Will Change Status Bar OrientationNotification
These two come from UIViewController and UIApplication, and they do appear in the docs.
The longest notification name:
QTCapture
(58)Connection Format Description Will ChangeNotification MPMusicPlayer
(58)Controller Now Playing Item Did ChangeNotification
Notification names tend to be very long in general, so I thought they deserved their own category. These two come from QTKit and iPhone’s MediaPlayer framework. These two frameworks (and media-related frameworks in general) had a lot of crazy entries in the result list, so I guess they must be not too fun to use…
And the longest notification in Cocoa (AppKit) was this one (from NSTextInputContext.h):
NSTextInput
(56)Context Keyboard Selection Did ChangeNotification
So, mystery solved :) Now I can happily go back to Cocoa coding, looking at the names in my code, and knowing it’s not the worst that could have happened…
7 comments:
J Bryan Price
I found your post after running across
automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers (70)
in UIViewController for iOS 5.
I'm sure glad it's not "autoForward" or something equally obtuse :)
Brent Royal-Gordon
Core Data's support for iCloud adds this monster notification to Cocoa:
NSPersistentStoreDidImportUbiquitousContentChangesNotification (62)
The Apple engineer who discussed it at WWDC (at least during the iOS Core Data session) joked that he had a hard time fitting it on a slide.
nomoral
why, why?
why do they do this to us??
Ramy
In core animation kCAMediaTimingFunctionEaseInEaseOut rofl
Choominator
MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification (74). Do I win this contest?
Kuba
@Choominator: OMG... looks like it's getting worse with every new version...
Marcel Weiher
The problem, of course, is the fact that all of these must be globally scoped, because Apple has forgotten how to use classes for namespacing.