Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

schmintan

macrumors regular
Original poster
Mar 1, 2007
181
0
i know a bit of c# and vb ( from windows work) and i recently purchased a mac to get a different perspective on the computer world ( and they are pretty!). i want to give objective c a go for writing coca apps. do i need to know C or C++ to become ok at objective C?
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
i know a bit of c# and vb ( from windows work) and i recently purchased a mac to get a different perspective on the computer world ( and they are pretty!). i want to give objective c a go for writing coca apps. do i need to know C or C++ to become ok at objective C?

Nope, you don't. Get Programming in Objective-C by Stephen Kochan. He doesn't assume any prior knowledge of C at all.
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
No you don't. In fact, some say it is harder for a programmer used to procedural programming (as typically used with C) to get used to object-oriented programming with a language like objective-C.

The barrier that you might run in to is that some books on learning objective-C do assume you already know C or C++. Just avoid those books.

A good one that assumes no prior knowledge of C is Programming in Objective-C: http://www.amazon.com/Programming-O...9611959?ie=UTF8&s=books&qid=1176820042&sr=8-1

Also, Apple has several good articles on objective-c and cocoa. Lemmie see... here's one directly to the objective-c tutorial: http://developer.apple.com/document...veC/index.html#//apple_ref/doc/uid/TP30001163.
And here's a link to a cocoa one: http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/index.html. Notice the "Related Reference" and "Related Documents" links on the left side; these are other useful, free links.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Well, Obj-C is a strict superset of C, so if you become proficient in Obj-C you will have learnt C.

But if you have any signficant previous coding experience you shouldn't have much trouble diving straight into Obj-C, if you have a good book at hand. Learning the language itself is relatively easy, it's learning what the Cocoa frameworks offer in features and shortcuts that will take time.
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
Objective C does not require any knowledge of any language or progrmming concept.

But, if you want to really know it all, after you have learnt Objective C, I recommend you take simple look at what plain C has to offer. Personally, I learnt C++ first and then moved to Objective C, and I see that I still need the low-level access C and C++ offer.

My advice. Start with Programming In Objective C by Steven Kochan, as others have suggested, then take a book on C and see the low-level functions C offers.

Personally, I couldn't have understood the memory management in Objective C if I didn't know about pointers in C and C++.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
As whooleytoo pointed out, Objective-C is a superset of the C language so you can't avoid learning the syntax and programming constructs/flow control etc of the C language. Perhaps your question should be do I need to learn the C standard library to use the Cocoa framework? I don't think you do but some of the functions in the C standard library are very handy.

b e n
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
lazydog is right, knowing how to program in straight procedural C will be very useful, even as a Cocoa programmer. There's still a lot you can't do directly from Cocoa, or can do more completely from C-based APIs, such as QuickTime, CoreAudio, CoreImage, CoreVideo, OpenGL, some Spotlight/metadata searching features, accessing FireWire and USB ports, custom UI, etc. You can do a lot from Cocoa, but not everything.
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
lazydog is right, knowing how to program in straight procedural C will be very useful, even as a Cocoa programmer. There's still a lot you can't do directly from Cocoa, or can do more completely from C-based APIs, such as QuickTime, CoreAudio, CoreImage, CoreVideo, OpenGL, some Spotlight/metadata searching features, accessing FireWire and USB ports, custom UI, etc. You can do a lot from Cocoa, but not everything.

HiRez - for the things you mention that cannot be done in Obj-C, are you implying that when writing in Obj-C and one needs to do these things, one can drop into C (from within Obj-C) to do things things?

If so, is this done by calling a C routine, or are there directives in Obj-C to drop into inline C? Or, is just a matter of coding the C within the Obj-C, since there are no Obj-C equalivalents?

(Am I making sense?)

Todd (I just ordered the Obj-C and Cocoa book dynamic duo pair mentioned above)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You just call C functions directly. Objective-C is implemented in C so you can use ALL of the C functionality directly. You don't need to use any special directives, bridges or anything like that.
 

MacDonaldsd

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
You just call C functions directly. Objective-C is implemented in C so you can use ALL of the C functionality directly. You don't need to use any special directives, bridges or anything like that.

Thats interesting to know.

Im quite proficient in C and its taking me a while to get my head around Cocoa/obj-c so your probably best going straight to obj-c :)
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
i know a bit of c# and vb ( from windows work) and i recently purchased a mac to get a different perspective on the computer world ( and they are pretty!). i want to give objective c a go for writing coca apps. do i need to know C or C++ to become ok at objective C?

If you take C#, and forget everything that has anything to do with objects, the rest is reasonably similar to C. If you take Objective-C, and forget everything that has to do with objects, the rest _is_ C.

If you know C#, then you know programming in general, you know object oriented programming, and you have some idea of C. That should be enough to learn Objective-C without problems.
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
Personally it helped me, but I've always been interested in programming and that, so I knew what he was talking about in the book. The Steve Kochan one, but I related it to my first programming book, and really it was a breeze to read cause it flowed really smoothly and he makes it like you've never heard of the word programming at all. So I suggest reading it, and heck read over some of the chapters again to build a better foundation. He even includes a C tutorial part in the book so if you read some of that then followed from chapter 1 or 2; you'd be good. Now if you want to make Mac OS X GUI apps then you'll need to learn both Objective-C (Obj-C for short) and Cocoa (cocoa is really easy as well).
Here's a simple program in Objective-C
PHP:
#import <Foundation/Foundation.h>

int main()
{
 NSString *hello = [[NSString alloc] initWithString:@"Hello world this is a string"];
 NSLog(@"%@", hello);
 [hello free];
 return 0;
}
 

jhande

macrumors 6502
Sep 20, 2006
305
0
Denmark
Oops my bad, I know it's release, I have not a clue why I typed free

Cuz the question was about C and you automatically dropped into malloc/free mode :D

As someone who is in the process of going from C -> Objective-C, I must admit this is probably the most painless transitions I've yet expreienced. There is one caveat though: Since it's a strict superset of C it is waay too easy to drop into procedural mode and just bang away. I've done that a couple of times when trying things out.

An excellent implementation, and Cocoa really is the bees knees compared to other libraries. But still having the standard library instantly accessible gives me a nice comfortable feeling :)
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
The only real knock I have on Obj-C is that while certain code snippets can be brief (thanks mostly to the many utility functions of the Cocoa library, like reading a file into a string in a single call), sometimes it can take a lot of lines of code and setup to perform a certain procedure, compared to more efficient languages such as Python and Ruby (these are especially strong at string parsing and collections manipulation). Some of the new features coming with Leopard should help (garbage collection, abbreviated iterator functions, etc.).
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
The only real knock I have on Obj-C is that while certain code snippets can be brief (thanks mostly to the many utility functions of the Cocoa library, like reading a file into a string in a single call), sometimes it can take a lot of lines of code and setup to perform a certain procedure, compared to more efficient languages such as Python and Ruby (these are especially strong at string parsing and collections manipulation). Some of the new features coming with Leopard should help (garbage collection, abbreviated iterator functions, etc.).

Yeah, the string handling especially. I love the simplicity and clarity of languages such as Delphi in this area.

Compare:

Delphi
Code:
Fullname := Surname + ',' + Firstname;

to Obj-C
Code:
[Fullname setString: [Surname stringByAppendingFormat:@",%@", Firstname]];
 

Masna

macrumors newbie
Apr 20, 2007
8
0
Personally it helped me, but I've always been interested in programming and that, so I knew what he was talking about in the book. The Steve Kochan one, but I related it to my first programming book, and really it was a breeze to read cause it flowed really smoothly and he makes it like you've never heard of the word programming at all. So I suggest reading it, and heck read over some of the chapters again to build a better foundation. He even includes a C tutorial part in the book so if you read some of that then followed from chapter 1 or 2; you'd be good. Now if you want to make Mac OS X GUI apps then you'll need to learn both Objective-C (Obj-C for short) and Cocoa (cocoa is really easy as well).
Here's a simple program in Objective-C
PHP:
#import <Foundation/Foundation.h>

int main()
{
 NSString *hello = [[NSString alloc] initWithString:@"Hello world this is a string"];
 NSLog(@"%@", hello);
 [hello free];
 return 0;
}

There's no need to supply NSLog with a brand new string, only to fill it with the hello instance. This makes more sense (considering NSLog takes an initial NSString instance argument):

NSString *hello = [[NSString alloc] initWithString:mad:"Hello world!"];
NSLog(hello);

Cheers!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
The message used to release objects is release, not free.

You could always write a category method :D

Code:
@interface NSObject (Free)
- (void)free;
@end

@implementation NSObject (Free)
- (void)free
{
    [self release];
}
@end
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
You could always write a category method :D

Code:
@interface NSObject (Free)
- (void)free;
@end

@implementation NSObject (Free)
- (void)free
{
    [self release];
}
@end

I can also go to the bathroom by making a stop at Colorado, first :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.