Search
Recommended for You

I Can C Clearly Now


There was a comment on the Editor's List noting that Objective-C book sales are up, presumably as a direct result of interest from potential iPhone programmers.

I say "potential" because the role of Obj-C is probably overstated, particularly by those who aren't actually doing iPhone programming. When I see some Java developers (presumably still smarting from Steve Jobs' assessment as Java as a "big ball and chain") claiming that Apple is scheming to force developers to use Objective-C, I just have to shake my head.

Because there are times that I really wish the iPhone APIs would let me use Obj-C.

Take a step back and look at the libraries that make up the iPhone SDK. All the stuff they adopted from third-parties -- OpenGL, OpenAL, and SQLite3 -- is programmed in plain ol' C (which Apple sometimes calls "procedural C" to distinguish it from Obj-C).

Of Apple's own frameworks, there's plenty of functionality that can only be accessed from C. The high-level media frameworks, like MPMoviePlayerController and AVAudioPlayer, are in Obj-C, but to do anything interesting with samples, you're in Core Audio and using C. For drawing custom graphics, you can either call the aforementioned OpenGL with C, or Quartz / Core Graphics, which is also C-only. This sort of makes sense from a performance perspective: the small overhead of Obj-C message dispatch could add up if done many times a second, which is more likely in media applications. Between sound, graphics, media, and game logic, it's highly likely that game developers rarely touch Obj-C, needing it only for the multitouch and acceleromer features exposed by UIKit.

Networking? Bonjour has an Obj-C wrapper, and the URL Loading System lets you get the contents of http:, https:, ftp:, and file: URLs with Obj-C, but if you want to open a socket connection to an arbitrary port on an arbitrary host, you'll be using C to call CFNetwork, if not BSD sockets itself.

Planning on accessing the user's Address Book? Pointer up, you're using C. Yeah, I don't get that, actually.

Even the Foundation framework is backed by the C-based Core Foundation, into which you sometimes need to call for certain little-used features, as detailed in Opt-In Complexity. To Apple's credit, switching between the two with toll-free bridging is pleasant and performant.

Even if you restrict yourself to the APIs with Obj-C wrappers, a grounding in C is enormously helpful for iPhone development. Every Obj-C object is ultimately a pointer, something that can be tremendously helpful when you need to call into your objects from procedural C code (I find I'm doing this a lot in Core Audio, where your asynchronous work needs to be done in plain C callback functions). With no garbage collection on the iPhone, the experienced C developer is keenly aware of memory management, even if retain and release (or CFRetain() and CFRelease()) are more pleasant than malloc and did-I-remember-to-ever-free-that.

In fact, one concern I have while co-writing the Pragmatic Programmers' iPhone book (currently in the last half of the last chapter... all Core Audio and haven't written a line of Obj-C in at least a week) is what kind of experience the typical newcomer will bring to iPhone development. I hate to set prerequisites, to say "go read these Obj-C and Cocoa books, then come back and I'll tell you what does and doesn't apply". I expect I can touch on the implicit background material in passing and let readers connect the dots of how it all works. But Interface Builder is so tempting, I suspect we are seeing a lot of Flash programmers jumping in and getting really burned by some of the sharp edges of C-style memory management, call syntax, and other hazards. We've sort of set our expectation as being "if you know a curly brace language, you're probably fine", mentally targeting C, C++, C#, and Java programmers, hoping that Ruby developers will be able to pick up the implicit C-isms along the way. But what's going to happen when web programmers, even those who are quite capable in JavaScript or ActionScript, see their first dereferenced pointer? It's not a pretty thought.

This is a tricky situation, not unlike how Java was originally so C++ like that some books would describe features as "X works exactly as it does in C++", a habit that fell by the wayside when people started learning Java directly, without the C++ background. At some point, we'll face a similar challenge on the iPhone: can we teach developers how to program the iPhone without requiring they pick up their C knowledge somewhere else first? Right now, so many developers are exposed to one or more of what I call the *C* languages (read "star C star", and interpret the wildcard characters as appropriate), that I think it's safe to assume that a sufficiently huge population of developers already meets these prerequisites. But as more and more developers cut their teeth on the OO scripting languages, like Ruby, Python, and ActionScript/JavaScript, we'll probably see more and more developers experience iPhone OS as their first C programming platform.

And at that point, would we be writing a "C for iPhone" book?

AddThis Social Bookmark Button
Comments (13)

13 Comments

Jesse Armand said:

I am very much agree with your opinions.

I think, motivation to learn a programming language would come from whether there is an implementation to use that language in a particular platform.

Since, iPhone is very popular, then it's a driving force for people to learn "how to program" for the iPhone OS.

I'm not sure there should be a necessity about "C for iPhone", but it would be better to write about a complete iPhone programming book, that would cover most of the low-level things under the Objective-C frameworks.

In other words, book about those things, which is not clearly covered on Apple's docs, and it should explain those programming topics in an easier way than the docs.

Liam Walsh said:

I'm one of those guys that did cut their teeth with OO / scripting languages, coming from an arts background and growing up with Flash, moving from processing to Java and getting excited by the iphone and diving right in, the *C* thing hurt a lot. Even a bit of dabbling in openframeworks didn't help much more than understanding the syntax a bit.
Objective C is pretty cool and very easy to learn (takes about a week) but for us Flash / Processing people the Apple framework is kinda limiting, we need openGL and coreAudio so we needed to learn C. Too many books DO focus on syntactical differences but assume I know the first thing about memory management, pointers and references. Wikipedia is no way to learn about this stuff. I'd love someone to write a book for us non cs background self-taught types.

Adrian said:

Glad to see you maniacs are still publishing your RSS feed without paragraphs.

jared said:

Liam:

The book you are looking for is the book we "cs background types" were asked to buy when we took our first programming class:

http://en.wikipedia.org/wiki/The_C_Programming_Language_(book)

C Memory Management 101, for the C runtime library and other libraries:

Learn what APIs allocate memory. Learn what API's de-allocate (free) memory. If you're allocating memory, know why. If you've allocated memory that you're not passing back to your caller, free it. If you're allocating memory that you ARE passing back to your caller, use conventions and documentation to make that explicit.


Pointers 101:

char a; //one byte

char *b; //*b (value-at b) is a char (like a)
// b is a memory address (a.k.a. a 'pointer')

&a //the address-of a, a memory address (like b)

In C, you can do assignment between things that are the same type, so for example:
a = 'A';
b = &a; //set b to the-address-of a
*b = 'B'; //set the-value-at b to 'B'

So even though we never manually reset the variable a, its value is now 'B'.

Paul said:

I was about to write basically what Jared just did.

If you want to program serious applications, you need to learn a serious programming language. You need to start with *C*.

I'll admit, I'm kind of a purist, and I hate the way Java programmers never really learn memory management; but there it is. M-M has to happen at some point, and if you start with a fluffy language that does it for you (usually poorly) and move into a limited platform like a mobile device where you've got to handle it yourself, there is no one to blame for your ignorance but yourself. If you want to go into deep waters, you have to learn to dive.

Though, it might be nice if someone put up a warning sign or two. :)

HombreE said:

Well, well...
kinda sort of confusion here.

basically when writing software that shall run on
HARDWARE -->you
a) write it just to "run"
b) or do it WELL

writing good software always means going deeply to hardware ( and especially for embedded and mobile ). so YES ,learn C . and be good at C.

and don't hesitate to learn assembly.
you bet. you'll never regret.

cheers for Asm*Lovers

ipod repair said:

I agree. Assembly is the best thing that'll ever happen to you.

Colin said:

Yet another pro C vote.

"The C Programming Language" is possibly the best-ever book written on *any* programming language.

And knowing C makes it relatively simple to learn most other languages.

Now, I happen to like perl and assembler, but Objective-C doesn't make me feel ill. A bit of OO can be good for you. I started on Obj-C (v.1) a couple of years back, but didn't really get into it - Objective-C's retain/release is as error-prone as pointer stuff.

And then someone decided that having to write getter and setter methods for each variable *was* a pain in the neck after all, and introduced properties.

And then, indeed, *for performance reasons* we'll use C anyway :-)

So,

Learn C. Learn Obj-C. Then mix and match. :-)

//
CGSize shadow_offset = CGSizeMake( -1.4, 1.4);
CGFloat blur = 0.0

CGContextSetShadow(cg_context, shadow_offset, blur);
//

That's a mess. How about:

//
[myCGContext setShadowOffsetWithSizeHavingWidth: -1.4 andWithTheSameSizeHavingHeight: 1.4];
//

or, better,

//
[myCGContext setShadowOffsetUsingSize: [CGGeometry createAndInitUsingADictionaryRepresentation [[NSDictionary alloc] initWithKey: @"width" andValue: [[NSNumber alloc] initWithDouble: -1.4] andAnotherKeyBeing: @"height" withItsValueBeing: [[NSNumber alloc] initWithDouble: 1.4]]];
//

Liam Walsh said:

@Jared:
Thankyou... I'm ordering a copy right now.

LX2 Man said:

Thank you, Colin, for your advice. I was just about to ask "what's the best book to learn C?", but see you've already stated the answer! Anyone have any recommendations of "best book to learn Obj C?" Thanks!

Title: Elegant feature of Black Berry Bold 9000

Overture:
The company at the back of the BlackBerry is Research in Motion (RIM). In 1999, The first BlackBerry phone was launched and since then, several pleasant models have been appeared in the market. The current BlackBerry product portfolio now endeavors at a broader target group of regular consumers. The BlackBerry Bold 9000 smartphone has obviously taken more than one thing into account.

Impression:
IThe BlackBerry Bold 9000 smart phone appears in a simple black box with the BlackBerry logo as the only enrichment on the outside. The included accessories are a headset, a data cable and a battery charger. Unfortunately, there is no software CD included; the software is available for download on the BlackBerry Internet site. The BlackBerry Bold mobile phone looks very stylish with a beautiful finishing touch. The back side of this mobile phone doesn't match the front in my opinion. However, during my test period with the Bold 9000 I received a lot of positive feedback to it. On one side of the handset two shortcuts are found for voice dialing and the camera function.

Stunning Qwerty Keyboard:
The front of the BlackBerry Bold 9000 handset clutches a spectacular display with below it, a full QWERTY keyboard. The monitor is crystal clear. It already managed to astonish one with its background picture. Furthermore, some videos were conveyed with the test sample, in which the quality showed to the fullest; one can easily watch a video this way! The display offers a resolution of 480x320. The full QWERTY keyboard is easy to use even for me with big fingers, the keys are completely accessible. After one day of sending text messages with this keyboard, you're addicted! The trackball, the same as on other BlackBerry phones, is also available on the Bold 9000 to navigate the device. The trackball works fine, although for scrolling through long lists such as the phonebook, an arrow pad would come in handy.

Phone Menu:
Shortcuts on the main screen of the BlackBerry Bold just like previous models. Opening the menu, a vast list with 26 icons appears on the screen. While everything is displayed at the same time, on one hand, this is rather inconvenient. On the other, it saves to scroll through the entire menu if you're searching. One will find selecting every icon time and again to remind yourself what it served for. The way in the menu proves to be a steady and solid operating system. The only thing I don't get is why the structure of the menu, neat and sleek, is not carried out in the settings menu, as you will now find a simple boring black text on a white background. This is a pity, since it makes things rather disharmonic.

MS Office:
The BlackBerry Bold smartphone comprises business functions such as displaying Microsoft Office documents. Word, Excel and PowerPoint files can be opened and viewed with the BlackBerry applications. The preinstalled versions only allow you to view the documents. To create a new document or adjust an existing one, you have to switch from the standard version to a paid premium version.

Music & Video:
The dazzling design of the audio and video player of the BlackBerry Pearl already astounded me. Let alone the multimedia player of the BlackBerry Bold. When playing video files, where the large monitor shows to the fullest, the quality is superb. The built-in speaker delivers sound of an astonishing quality and if desired, at high volume. The BlackBerry Bold 9000 supports many file formats, even Divx.

Internet:
The Push-mail function on the BlackBerry alerts you wherever you are immediately new messages arrive. To open the attachment files is ever so easy, although editing is usual impossible. Mail accounts can be managed via a special BlackBerry Website. The BlackBerry Bold 9000 offers the opportunity to select and copy parts of texts which is a handy functionality that is not often found on a mobile phone. The Internet browser is easy to operate at a convenient speed. The only disadvantage is formed by the many slide bars that appear if a website consists of different columns, which makes it nearly impossible to navigate. One example is the Microsoft Outlook Web Access, you simply cannot use this page because of all the slide bars.
Blackberry Bold Wi-Fi, GPS and Maps
Simple and Straight forward, lower your cellular costs and get service in areas where network coverage may be limited or unavailable, with Blackberry Data Services over Wi-Fi networks. With built-in GPS and Maps you can easily pinpoint where you are and where you want to be.

Speed Network:
The phone comes with a 624 MHz processor complete with high speed HSDPA network. The built in 3G HSDPA technology allows the user to enjoy high speed connectivity, high rate data transfers & multitasking skills on the BlackBerry Bold 9000. The user can enjoy EDGE & GPRS technology which provides fast data transfer rates when transferring files. The 3G Smartphone supports both Bluetooth connectivity & USB connectivity which gives the user a choice of connection options when connecting their Smartphone to other compatible devices. The Wi-Fi connectivity allows the user to connect using a wireless connectivity to BlackBerry data services over a Wi-Fi network. This stylish Smartphone works on a GSM quad band network which covers GMS 850, 900, 1800 & 1900. The BlackBerry Bold 9000 is a truly business focused Smartphone which comes with easy to use communication, Internet & entertainment features which are easy to use.

Desktop Manager 4.6:
No software standard incorporated with the BlackBerry Bold 9000. This software can be downloaded from a special Internet page. The BlackBerry Desktop Manager 4.6 is well thought-out as well as straightforward. It offers a main menu with five options: Application management, Backup, Multimedia management, Synchronisation and Data transfer from a second BlackBerry.

Software application:
These clear software application consents to get the most out of the BlackBerry very fast. These mobile phones usually be associated with rather complicated software, but not the BlackBerry Bold 9000. If your BlackBerry Bold handset is connected to a computer, you can also select the mass storage mode which allows you swiftly manage the data on a memory card without having to install software.

Phone Memory:
The standard memory of 1GB lets you store several multimedia files on the BlackBerry Bold. However, if you own lots of music, and in particular for video files, 1GB is rather skimpy. Thankfully, the Bold 9000 offers the possibility to enhance its memory capacity with a microSD/SDHC memory card. The BlackBerry Bold supports memory cards up to 8GB.

Battery:
The 3.7V Lithium Polymere battery, according to the specifications will last for 13 days in standby and offers a talk-time of 4.5 hours. In tested period the mobile phone, I used the media player quite frequently and also the Internet functionalities. The battery then lasted for approximately two days which is fairly reasonable.

Culmination:
The Blackberry Bold 9000 smartphone embodies elegant design – without sacrificing the features or functionality you come to expect from Blackberry. The BlackBerry Bold 9000 is a mobile phone with striking design as well as fantastic BlackBerry functionalities. The large, crystal-clear widescreen monitor presents a perfect reproduction of many file formats. The Internet browser is easily accessible.The 3G internet speed and WiFi all connection options are at hand. Only the Internet pages divided in columns that the Bold 9000 effort with. The enthusiastic applications enable opening Microsoft Office files with the BlackBerry. To make adjustments to the files, you have to acquire a more enhanced software package. Thanks to the Push-mail function, which allow little chance to miss an incoming message, and the full QWERTY keyboard lets you answer immediately without a problem. The only minus on this handset is its integrated low resolution camera. Although we don't think it diminishes the value of this BlackBerry. Personally, I am delighted with the qualities of this BlackBerry Bold 9000. And if I have the urge to make pictures once in a while, I will bring a regular digital camera.

Thanks

Black Berry Bold

nikde said:

Shortcuts on the main screen of the BlackBerry Bold just like previous models. Opening the menu, a vast list with 26 icons appears on the screen. While everything is uggs displayed at the same time, on one hand, this is rather inconvenient. On the other, it saves to scroll through the entire menu if you're searching. One will find selecting every icon time and again to remind yourself what it served for. The way in the menu proves to be a steady and solid operating system. The only thing I don't get is why the structure of nike air the menu, neat and sleek, is not carried out in the settings menu, as you will now find a simple boring black text on a white background. This is a pity, since it makes things rather disharmonic.

Anonymous said:

Shortcuts on the main screen of the BlackBerry Bold just like previous models. Opening the menu, a vast list with 26 icons appears on the screen. While everything is
cheap ugg boots displayed at the same time, on one hand, this is rather inconvenient. On the other, it saves to scroll through the entire menu if you're searching. One will find selecting every icon time and again to remind yourself what it served for. The way in the menu proves to be a steady and solid operating system. The only thing I don't get is why the structure of women ugg bootsthe menu, neat and sleek, is not carried out in the settings menu, as you will now find a simple boring black text on a white background. This is a pity, since it makes things rather

Leave a comment