Note: This article was cross-posted from Brad’s personal blog: Naming Things is Hard
Over the last month at Bendyworks, I’ve been pairing with Jaymes on our latest initiative: adding iOS development to our repertoire. As a Ruby developer learning Objective-C and Cocoa, you might expect me to be a bit put off by a number of things, and you’d be right. But I can appreciate static-typing and immutability-by-default (hell, I’ll even applaud that)… the one thing that irks me most—and yet could be fixed rather easily—is the ridiculously long method names.
“That seems an odd mountain to die on,” some of you might be thinking. Well, what kind of programmer would I be if I didn’t have strong opinions?
But it’s not just the long names that bug me… it’s that they’re unnecessary.
You see, in Ruby, despite dynamic variables effectively globalizing the scope of applicable methods, we still use names like
join. So, you could potentially call
join on a stream object (probably not what you intend), and most likely receive a runtime error.
The static nature of Objective-C, however, confines the available methods you can call on an object to that of its statically declared type, lest you receive a compiler warning. And we all treat warnings as errors, right? So when you have an NSArray object, why are we using
componentsJoinedByString: instead of
joinWith:? Hell, why can’t we just have a
join which does a reasonable default? It’s not like these short method names will be available to objects of type, say, NSStream.
So, after scouring the GitHub tubes, I found ConciseKit, a collection of methods on core Cocoa classes that exhibit a more… Ruby sense of style. While the library had a wonderful start, I felt it needed a bit more functionality… so I wrote
$join: on NSArray. I also wrote a simple
$split on NSString. And thanks to the wonder of pull requests, these additions are now available on the canonical repository.
I’m not a huge fan of prefixing every ConciseKit method with
$, but the original author made a design choice, and I suppose I can live with an extra character. It’s the
componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet] which could have been written as
$split that I cannot abide.
In any case, I highly recommend looking into ConciseKit for your next Cocoa project.