What are the benefits of the design of the queue generation / retrieval APIs as opposed to having helper functions that simply pass along the default value at the time they introduced the API?
Examples:
dispatch_queue_global_t dispatch_get_global_queue(intptr_t identifier, uintptr_t flags)
dispatch_queue_t dispatch_queue_create(const char *label, dispatch_queue_attr_t attr)
The necessitation to send magic values such as NULL and 0 as parameters seems a bit verbose and was curious if there are any benefits or the motivation for designing them in this way since it seems that introducing the new methods would be a non-breaking change.
That said, any benefit to dropping down to C rather than exposing the dispatch queues via Objective-C instead?
For you? Probably not. In general? It’s not uncommon for folks to write programs that can’t use Objective-C, and those folks rely on the C API.
Keep in mind that there is an Objective-C API that’s the conceptual twin of Dispatch queues, namely NSOperationQueue. As I like to say, NSOperationQueue is to dispatch_queue_t as NSObject is to malloc. There are good reasons for Objective-C code to call malloc, but most of the time it’s better to subclass NSObject and then create an instance of that subclass. Similarly, there are good reasons for Objective-C code to use a Dispatch queue, but most of the time an NSOperationQueue is a better choice.
Having said that, I’m definitely in a the minority here. There are lots of folks who are much more enthusiastic about Dispatch than I am.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"