Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 2, 2005, 02:56 PM   #1
prophet621
macrumors member
 
Join Date: Jul 2005
Difference between C and Objective-C?

I've been considering learning a programming language for a while now, despite being told I'm probably too old to learn (I'm 33) I have narrowed down my choices to Python, C or Java. There are a few types of apps I would like to write for OSX but also be able to use them on Linux as well. As for using my created apps in OSX I read that Java can be used but is slower and not as efficient with memory. I also read that I can import Python code to Objective-C to use.

What is the difference between C and Objective-C? I have searched on Google but not knowing anything about either the answers seem to be a bit too technical. If I learn C will Objective-C be fairly easy to grasp? My concern with C is it looks confusing. Everytime I look at a C book I can't help but wonder how anyone remembers all of this and that's just the early learning parts.
prophet621 is offline   0 Reply With Quote
Old Oct 2, 2005, 03:50 PM   #2
gekko513
macrumors 601
 
gekko513's Avatar
 
Join Date: Oct 2003
C is an "old" programming language. It is quite low-level, that means it is quite close to assembly and the machine code that actually runs on the processor. It is a procedural language. In a procedural language you focus on solving problems with step by step recipes. Recipes can be reused, this is called a function. As programs grow larger functions will typically be grouped out in separate files based on functionality.

Objective C keeps all aspects of C and allows you to build programs exactly the way you would do a C program if you want.

In addition Objective C adds syntax and semantics that allows for object oriented programming. Object oriented programming differs from procedural programming by focusing on grouping data and methods of manipulating this data in classes.

Usually you will be able to write any program using either C or Objective C, the difference is the approach you take to solve the problem. Some find it easier to think procedural for small problems, but objective oriented design has advantages when it comes to tackling large problems. First of all because it becomes easier to divide the problem into subproblems and submodules that can be developed and tested individually. Secondly because it is easier to reuse your own or other's modules.

As for the problem of remembering everything. For the vast majority of us it is impossible to quickly memorize all aspects of a programming language straight away. You're going to have to keep books and other documentation handy at all times. The best way to learn is to practice. Create small programs to test, learn and understand new things as you go along.

Last edited by gekko513; Oct 2, 2005 at 05:24 PM.
gekko513 is offline   1 Reply With Quote
Old Oct 2, 2005, 03:51 PM   #3
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
There's two schools of thought.

1) Learn C THEN learn objective C.
2) Learn Objective C and the bits of C you need as you go along.

If you don't know C then the Kochan book is a good place to start as it covers the C you need as you go along.

As for the differences. Objective C is a superset of C - which means that everything that is in C is in objective C. It adds object orientated structures like classes etc. C is a simple (in design not use) procedural language that doesn't do object orientated stuff. Most of the stuff you'd recognise as objective C programming on the mac actually comes from using the cocoa frameworks which either wrap around or replace the nasty scary C API that is called Carbon. Sometimes this wrapping of the C API incurs a small performance penalty and sometimes it doesn't.

There is a very common misconception that a 'Cocoa' program will be automatically be faster than a carbon one - maybe because Cocoa is the newer API. This is incorrect. Actually the opposite could well be true. Where Cocoa and objective-C really score is in speed of application development and in the things you get for free just because you're using Cocoa. Many see that the increased speed of application development you get when using cocoa outweighs any minor performance penalty you may incur.

In your case your problem is that you want cross platform programs. Cocoa is only on the mac thought there is a less well developed version called GNUstep that works on other platforms. There are other cross platform approaches - realbasic, java, C++ and the QT frameworks are a few examples.
caveman_uk is offline   0 Reply With Quote
Old Oct 2, 2005, 05:07 PM   #4
mrichmon
macrumors 6502a
 
Join Date: Jun 2003
Quote:
Originally Posted by prophet621
I've been considering learning a programming language for a while now, despite being told I'm probably too old to learn (I'm 33) I have narrowed down my choices to Python, C or Java. There are a few types of apps I would like to write for OSX but also be able to use them on Linux as well. As for using my created apps in OSX I read that Java can be used but is slower and not as efficient with memory. I also read that I can import Python code to Objective-C to use.

What is the difference between C and Objective-C? I have searched on Google but not knowing anything about either the answers seem to be a bit too technical. If I learn C will Objective-C be fairly easy to grasp? My concern with C is it looks confusing. Everytime I look at a C book I can't help but wonder how anyone remembers all of this and that's just the early learning parts.
You're never too old to learn something new. Programming is no different. The other posters have given a broad overview of the differences between the languages you mention so I won't repeat that stuff.

Your concern with C being confusing is strange since the "early learning" parts of a book on C will be almost identical in the details to the early parts of learning Objective C and Java. Python has a few small differences but basically all the languages you mention have broadly the same syntax.

You remember the details as part of the learning process. If you don't feel that you are able to get this stuff straight then maybe programming is not for you. On the other hand, it is possible that the C book you were looking at was intended for people who already have coding skills and thus was explaining things in terms that an experienced programmer would understand. If this is the case then you should look for another C book to start with.

In terms of language choice, Java is probably your best bet as a starting language. Python is good but there are a limited number of books on Python coding. C is a little raw and quirky in many respects. Objective-C is a nice language but the dirth of introductory programming books may make it hard to get started with.

The basic syntax and concepts from Java are mostly the same as the syntax in C and Objective-C. If your aim is Mac programming then starting with Java you will get to understand programming and get an understanding of object-oriented programming. Then, if you find that Java is limiting you the jump to Objective-C is relatively easy.

Claims that Java is slower and less efficient with memory are technically accurate in some cases. But in practice you are very unlikely to find this a problem. Also, the way Java deals with memory means that there are many programmer errors that come up in C and Objective-C that are impossible to make in Java. The result is that the programmer is more efficient since there are fewer possible errors to be made in Java. Java also mostly helps you avoid the difficulties associated with writing applications to run on different operating systems (such as Linux and OS X).
mrichmon is offline   0 Reply With Quote
Old Oct 2, 2005, 11:05 PM   #5
prophet621
Thread Starter
macrumors member
 
Join Date: Jul 2005
Thanks for all the replies and the clarification on the differences.

A friend at work today let me borrow a C for dummies book. I know the dummies books are the most basic and barebones of learning tools but they tend to make it easy to grasp the very basic concepts so the other books aren't nearly as alien when you look at the tutorials and can begin to build on the basic knowledge you have. The other C book for beginners I have (can't remember the title at the moment) seems only for beginners for a few chapters and then takes off with terms that you're sure they haven't covered and can't find them anywhere. Suddenly it's like someone else started writing it and forgot it was a book for someone with no programming experience.

Later this week I'm going to go out a Java book but from posts here and all my reading, Jave borrows heavily on the C/C++ syntax so I'll atleast have a basic understanding of that. I don't think the first dozen chapters of C for dummies will ruin me too bad for picking up Java. I know there are hundreds of beginner tutorials but I like having the text and explanations right beside me, not in another window.

Thanks again for the help, I'm sure I'll be back asking more questions as I learn.
prophet621 is offline   0 Reply With Quote
Old Oct 2, 2005, 11:53 PM   #6
crackpip
macrumors regular
 
Join Date: Jul 2002
One thing to keep in mind is that Apple has stopped active development for the Java-cocoa bridge (which allowed you to write native cocoa applications using Java). This means that new features added to cocoa will be unavailable to cocoa programs based on Java, and your program may eventually be incompatible with the latest versions of OS X.

The Python-cocoa bridge is its own project, not handled by Apple, so its continued development is more secure.

Also, just to correct a statement of caveman_uk's. Cocoa (being the API of NeXTStep) is an older API than Carbon. Carbon was created by Apple (I believe between their release of Rhapsody and the Developer previews) to allow programmers to continue using c or c++ instead of switching to obj-c. They then wouldn't have to completely recode their older applications. I think being not as polished and allowing developers to keep their "legacy" code gave it a bad reputation. But Carbon has evolved very rapidly and according to some of my friends (my experience with carbon is non-existent), this bad reputation is no longer deserved.

crackpip
crackpip is offline   0 Reply With Quote
Old Oct 3, 2005, 04:00 AM   #7
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Quote:
Originally Posted by crackpip
Also, just to correct a statement of caveman_uk's. Cocoa (being the API of NeXTStep) is an older API than Carbon. Carbon was created by Apple (I believe between their release of Rhapsody and the Developer previews) to allow programmers to continue using c or c++ instead of switching to obj-c. They then wouldn't have to completely recode their older applications. I think being not as polished and allowing developers to keep their "legacy" code gave it a bad reputation. But Carbon has evolved very rapidly and according to some of my friends (my experience with carbon is non-existent), this bad reputation is no longer deserved.

crackpip
You're quite correct. I forgot about Cocoa's pre-Mac OS X existence at NeXT. I was thinking of it's introduction on the mac where it was a new thing compared to the old procedural API. Thanks for the correction.
caveman_uk is offline   0 Reply With Quote
Old Oct 3, 2005, 05:34 AM   #8
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by caveman_uk
You're quite correct. I forgot about Cocoa's pre-Mac OS X existence at NeXT. I was thinking of it's introduction on the mac where it was a new thing compared to the old procedural API. Thanks for the correction.
...but IMHO its bad reputation is deserved! It's ugly. Really ugly. I mean, it still uses Pascal data types (!), and others from the very early years of the Mac Toolbox, among other kluges. This would be fine if you never had to deal with it writing Cocoa apps, but in my experience you may have to, possibly frequently. Vast areas of Apple's APIs have not been "Cocoaized" yet, thus you must dig into the unfriendly world of Carbon to access them. These include CoreAudio, CoreImage, and most of QuickTime. Plus many more obscure but important things like "how do I get a system clock with a resolution of milliseconds, microseconds, or nanoseconds?" Look at Apple's own "Cocoa" code and you will see much of it is blotted with Carbon calls where no Cocoa equivalent is available.

(Note that I'm unclear whether things like CoreAudio and QuickTime are officially owned by the Carbon frameworks, but the APIs are similar, and there is much dependency on the same conventions and data types.)
HiRez is offline   0 Reply With Quote
Old Oct 3, 2005, 06:26 AM   #9
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Yep, vast tracts are still Carbon only and it's a real PITA to use. I mean how much effort would it take to write cocoa APIs for these? Some of these features are quite new (for example Core Image, Spotlight) and still Apple punted them out without a Cocoa interface.

I still have the scars from battling the security framework. Guess what the first thing I did was once I understood it? Write a cocoa wrapper around it.
caveman_uk is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: Learning objective-C? Curax iPhone/iPad Programming 4 Sep 7, 2013 12:28 PM
example objective c code arkmannj iPhone/iPad Programming 2 Jul 26, 2013 11:05 PM
Problems with Objective-C++? frank100 Mac Programming 5 Aug 8, 2012 05:49 PM
Objective C Syntax nashyo iPhone/iPad Programming 6 Jul 4, 2012 12:56 PM
Does the storage difference justify the $$$ difference? Redjericho iPad 19 Jun 27, 2012 03:22 PM

Forum Jump

All times are GMT -5. The time now is 10:56 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC