How to leverage the *C* in Objective-C?
I've been doing iPhone development full-time over the last couple of months.
Having previous experience only in OOP, I've relied hea开发者_Go百科vily on Apple's APIs, which eventhough majestic I must reckon, led me to write code that in retrospective looks like a weird mix of ruby/smalltalk with added boilerplate.
So I'm thinking I'm missing out, and ordering K&R. Yet I wonder how what I'll learn, can specifically be put to good use in iOS work, without fighting against the devices' API and the whole OO pardadigm ?
The lower level APIs are largley in straight C, perhaps you'd like to explore them? For example Quartz 2D has a C API.
Objective-C is a superset of C. You can intermingle Objective-C and C function calls, statements, etc.
So for example, if you prefer Posix sockets to NSSocketPort, you can just mix in the C socket functions wherever you want. Or, if you wanted to keep it a little more object oriented, you could wrap C statements in an Objective-C function call that would isolate your C code from the rest of your Objective-C code.
Something that might help you understand the relationship between C and Objective-C would be to create an Objective-C wrapper for some C code. I’d recommend writing a simple iPhone app scripted in Lua. That should be enough of a project to really look at the C.
Not learning C is not missing out on anything.
I almost agree with @jeff except that I don't see why so many beginning Objective C programmers go straight for the iPhone stuff when they could be running a Mac app with much less hassle and convert it later.
But yes, buying a copy of K&R would be a very good idea (as well as getting a copy of the C90 or C99 standards, if you can afford them). In fact, I have a book on iOS games that suggests going straight to vanilla C for a lot of the low-level stuff to cut out the messaging overhead for performance's sake. Essentially, you're not doing anything you're not "supposed" to do by using C functions; the C library is still there to be used, so you aren't doing anything particularly strange or kludgy.
精彩评论