• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how is C often used in Cocoa, if at all?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how is C often used in Cocoa, if at all?


  • Subject: Re: how is C often used in Cocoa, if at all?
  • From: David Remahl <email@hidden>
  • Date: Tue, 11 Feb 2003 23:01:51 +0100

Hi Ben,

Hiyer,

I'm currently learning C before I get stuck into Objective-C and Cocoa, and am just skimming this list in preperation - to see what's going on.

And I'm wondering if C is used much in writing Cocoa applications? It doesn't seem to be, from what I've read on here, or have I got the wrong impression there?

It _is_ used quite a lot in serious development. You may not need much besides ObjC style message passing if you're creating an application that runs command line apps using NSTask or that creates

How often, and how is C often used from within Objective-C and Cocoa, if at all? Are there some things that lend themselves well to being written in straight C, and other things that don't? Which sort of things? Is it just a matter of preference and ends up being easier not using C?

First of all, Objective C is a rather slim addition to the C language. As far as syntax goes, it adds little but a preprocessor directive, a few @whetever instructions to the compiler, a syntax to define methods and another syntax to call them. It is also quite simple to see through this added syntax sugar and realize how Objective C is implemented in C. Therefore, the rules:

- that decide what the definition of an expression is
- that dictate operator precedence
- that dictate what a variable is
- that defines the syntax of loops and conditionals
- etc

are common between the two languages. And we can all agree that expressions, operators, variables and loops are common components of every Objective C program :-)

Objective C is just an object oriented extension to the language C. Anything that is C is also Objective C. There are definitely some things that are better done in C, mainly for performance reasons. For example, NSArrays (the Cocoa class for arrays) carries a lot of power, but also a very significant performance pentalty compared to C arrays or even Core Foundation CFArrays.

Another example is that it isn't smart to compose an image of 1 000 000 separate pixel objects. Likewise, it isn't smart to treat a stream of data as separate byte objects. In Objective C we have the freedom to choose to use C for some tasks (ie, store image data as plain data - as NSBitmapImageRep does) and enjoy the superior abstraction that OOP brings for other tasks.

I know these are very broad questions but I'm just trying to get an understanding of how C fits in generally with Obj-C and Cocoa.

If you make sure you understand C well, before you start learning Objective C, it will soon be clear to you the different scopes of the two mindsets :-).

/ Rgds, David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: how is C often used in Cocoa, if at all?
      • From: Ben Dougall <email@hidden>
References: 
 >how is C often used in Cocoa, if at all? (From: Ben Dougall <email@hidden>)

  • Prev by Date: [JAVA] NSDictionary vs Hashtable etc
  • Next by Date: Re: help needed with OO concepts when copying
  • Previous by thread: Re: how is C often used in Cocoa, if at all?
  • Next by thread: Re: how is C often used in Cocoa, if at all?
  • Index(es):
    • Date
    • Thread