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

prophet621

macrumors member
Original poster
Jul 31, 2005
86
0
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.
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
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.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
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.
 

mrichmon

macrumors 6502a
Jun 17, 2003
873
3
prophet621 said:
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).
 

prophet621

macrumors member
Original poster
Jul 31, 2005
86
0
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.
 

crackpip

macrumors regular
Jul 23, 2002
210
0
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
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
crackpip said:
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.
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
caveman_uk said:
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.)
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.