Apple Complaint #7: Weak Networking API
I actually had a different complaint slated for today’s slot until Brent Simmons posted a link to this Stepwise article—a comparison of open-source, Objective-C-based networking libraries available to Cocoa developers. The fact that Cocoa developers need concern themselves with such a thing underscores what I think is an important shortcoming of Cocoa’s. As Aram Greenman, the article’s author, observes:
With network capabilities required by so many applications, Cocoa developers often wonder why Apple doesn’t provide a complete Objective-C solution for network programming. While it’s possible, and often practical, to [use] the C sockets interface in Objective-C code, it doesn’t provide the ease of use Cocoa developers expect.
At the risk of turning this series into a list of reasons I like Java better than Cocoa (which I don’t), I’ll add that this statement brings to mind a frequently noted factor in Java’s success: the presence of an easy-to-use, full-featured networking API to hide the complexity of the operating system’s lower level sockets implementation.
Unlike Java, Cocoa lacks a true Socket class (don’t be confused by NSSocketPort, which does nothing to hide the native sockets interface). Rather, with the exception of a few hooks in NSFileHandle, the framework primarily concerns itself with very high level networking interfaces such as NSURLHandle (which currently supports only HTTP—and even then only in such a basic way that Dan Wood felt compelled to develop his own CURLHandle) and Distributed Objects. Developers wishing to work at a lower level (to implement, say, the FTP protocol) are left to deal with BSD sockets.
Given the importance of networks to modern applications, I think it is fair to say that no modern development environment is complete without a strong networking API. Unfortunately, this seems to be another area where Cocoa is lagging.