Advice on how to learn C / Objective-C

boyfarrell

Registered
Hi all,

Have you any suggestions on books to learn Objective-C? I have very little C and no object oriented experience. I mostly program in Matlab.

Where do I start? Is it better to learn C (beacause there seems to be more books on that) and then once I'm happy with the syntax etc, pick up a objective-C book at learn about objects?

Can anybody explain, why objective programming is seen to be the best? What is a damn object anyway !! Grrrrr! :confused:
 
C or Obj-C that is question? It really depends on what you want to do with your learned skills. If it's mathly types of things, C is what you want to learn first. If it's pretty GUI things, go for Obj-C and Cocoa. And if you have the developer tools installed on your system, you should have a fairly complete library for learning Obj-C and Cocoa. Look in the developer tools directory.

And, I always have to mention . . . the scripting language python. It's a great way to learn about objects and improve your programming skills. Oh, and it's already installed on your computer (10.4, 10.3, and I think 10.2 too).
 
Buy some books :)

I have 2 that i'm working through - Learning Objective C, and Cocoa programming for Mac OS X.

Objective C is really weird, but just needs some adjusting.
 
Thanks,

No It won't be GUI at all. I hope to just use C or C++ or Cocoa etc to do the number crunching then save the data created to a .txt file and use matlab to display the information. I think matlab has a C compiler inside, so you can even call your C code from matlab an use it functions from there, they are called .mex files I believe. Although I don't know much about it.

Ok I'll look up Python (when I have my mac; I'm changing soon but currently own a PC laptop), sounds interesting... You seem to imply that is a good development language i.e. simple etc ... I will read about that.

I suppose the other thing is if I program in C then my code is cross-platform, is this true with Objective-C and the others...

Drarok, what do you mean objective C is weird?
 
Just go for straight C. It's easier, less complex and if all you are interested in is number crunching, you don't need to bother with Object Oriented programming. It'll just get in the way of doing things.

Python isn't really suitable for numerical applications. It isn't particularly fast, even with the additional SciPy packages that are made specially for scientific computing. My experience has been that it is slower than Matlab. So if you're dropping Matlab due to it's lack of speed, Python is not a good choice.
 
Thanks for the advice, Viro. Yeah that seems to make sence, it's the conclusion that was dawning on me too.

I guess if I program in C (or even objective-C if I want to learn it for fun in the future) I can easily program on both my PC at work at my mac laptop? Is this correct?
 
C is easily portable to other platforms, Linux and Windows included. Objective-C is ... interesting. The language should be supported on any platform that has GCC (the compiler used by Apple, Linux and is available on literally any machine), but the associated libraries like Foundation may not be.

Stick with C, then if you feel adventurous go dabble with Objective-C.
 
Yeah that is good advice.

However ...

The bit of my programme that number crunchs, I will write in C. But I think by the nature of what I'm doing (modelling some physical system) would really benefit from an objective approach. I could see how in the future it would be really easy to make generalisations of my biggest object, change a few things around, and describe a new system.

I guess this doesn't make much sense to you because I know to what I'm refering, but needless to say I think I have 'seen the light'!

(I can fill you in on what I'm doing, if your interested, your a researcher too right?)

Thanks for your help!

Dan

By the way:

I found a great book on the objective approach, 'An introduction to Object-Oriented Programming', Timothy Budd. Have just spend half an hour reading the first 2 chapters and I understand what the whole point of objects is now! His approach is quite interesting too. He discribes the reasoning behind object-orientation, not through any one language, infact here the different systaxs are seen as stumbling blocks to 'getting the point'. Latter when he introduces the concepts more formally code is included in 4 different languages; C++, Smalltalk, Objective-C and Object Pascal (this is in the 1st ed. In the 2nd he also includes Java). Anyway, things are making sense; I love that feeling!
 
Objective-C is fine if you want to do that. A bit less supported and known among the unix people, but there is a cross-platform NextStep/Obj-C implementation called GNUStep. Nice thing. Programming in Objective-C is a well written introduction which doesn't assume any programming experience or specific development platform; the author is a Mac programmer, but there are instructions for development in a GNUStep environment as well.

Obviously, Objective-C is the choice if you may want to move on to GUI development later, and/or learn Apple's performance/multithreading frameworks.
 
boyfarrell said:
Yeah that is good advice.

However ...

The bit of my programme that number crunchs, I will write in C. But I think by the nature of what I'm doing (modelling some physical system) would really benefit from an objective approach. I could see how in the future it would be really easy to make generalisations of my biggest object, change a few things around, and describe a new system.

I guess I'm quite jaded with the Object Oriented (OO) approach, coming from an engineering background and moving to a more scientific background. There is a fine line between an engineer and a scientist. I can't remember the source but here is a quote that best sums it up: "Engineers learn to build, scientists build to learn". And that is a very important distinction!

OO is largely an engineer's tool. If you're going to build a good OO system, you need to spend loads of time analyzing the problem and designing a solution. Coding accounts for very little when building a proper system. This is a good approach, when you are trying to build well specified systems that will last for years and years with many people working on maintaining it down the line.

If you are a scientist, this can kill your research if you aren't careful. When you are a researcher, you build systems to learn. Your requirements aren't clear, and so you need a way to quickly build a system. If you find that system doesn't work or produce the results you desire, you move to a different system. A lot of throw away code is written. This is a reason why MATLAB is so popular among scientists. It doesn't enforce any programming paradigm on you, and allows you to quickly implement your ideas to test them out. To do such a thing with OO is ... suicide if you skip the analysis and design phase, difficult and time consuming if you _do_ the analysis and design phase.

That said, my work with neural networks has been largely done without OO, but with a more structured approach (functions and records). It's been working fine, and I am at the stage where I can actually see clearly enough the problem that I'm trying to solve. Hence, after 2 years of experiments, I am now going to try and write my simulation code in an OO manner, in Java. Reasons for Java? PM me if you're interested. I'm not going to diss Objective-C on a Mac forum :).
 
ksv, thanks for your tip. I acutally found the GNUstep site before. They implement a version for windows too (I will have to use windows at work and mac at home - just for a little longer anyway! :0> ). From what I've read,

http://www.gnustep.org/resources/sources.html#windows

this seems that this is just the 'base' i.e. there are no GNUstep text editor or debugger included. I guess nobody will know here, but is there a good objective-c text editor etc for windows ... ?

My library doesn't have a copy of that book! Grrr! But I'll get in from amazon in a few weeks. At the moment, I'm mostly building up my experience in C.

Thanks again for you help!
 
I'll vouch for that book, too. That's one of the ones I'm reading. It starts off nice and slowly, introducing new ideas one by one.

I meant ObjC is weird in that object methods are called in a completely new way:
Code:
objInstance = [[myObject alloc] init];
[objInstance setIntegerValue: 10];
[objInstance print];

Non-object methods are called in a standard way, though.
Something( Param1, Param2 );

Just gets a little confusing. I'm sure I'll get used to it eventually.
 
I guess I have the advantage here because I'm not use to any programming language! :D but there does seem to be a hell of a lot of square brackets floating around in objective c!

In response to Viro:

I see what you mean when you talk about scientist building to learn, it true. Iftact all the learning has already been done! The equations and method for solving have all been worked out, I'm just using C to number crunch, the code that I have already written in matlab.

But then I can also extend this approach by making objects that know how to solve the basic equations (not that basic I'm using 4D and 5D matrices!) for a certain input data. The great thing about what I'm working on is that as the system grows, the base unit doesn't change. All that changes is the interactions between the base unit.

In systematic approach (like matlab) this would require a bit more thought to program that with objects I think... but hey, who am I to know I'm just strating out! I will report with my progress!

Thank you for your warning too. I need to program to get results and write papers! So getting bogged down in a programming language would be a disaster. I think I will still use matlab as a quick development environment, but will try to implement it over into C once I'm happy with the algorithms.

Thanks for your help.

Dan.

PS - anybody know how to get objective-c running on windows?
 
Re: ObjC on Windows - for just basic Objective C stuff, nothing from Foundation, you can use Cygwin. When installing, make sure you install all the relevant libs. I think you have to go into Development->GCC (Look for anything mentioning Objective-C in there). That's how I've been practising at work :)
 
I program in MATLAB for my research too, and I'd definitely recommend C for fast number crunching. The advatntages of MATLAB are that it hides a lot of things from the user, which is great when you're starting out since it makes things easy for you.

It's slow as hell though, which is why C is a good choice. C does have a steep learning curve but you should recognise some of the syntax from MATLAB. Be warned though that the language requires you to be much more specific than you have been used to!
 
Another advantage of C if youre using Matlab is that you can call Matlab functions from C and C functions from Matlab. Have a look at the Mex interface.
 
Yeah,

That MEX stuff is a complete mystery to me! But in a nut-shell: If I re-write my matlab code as c, matlab can run it on a much lower level of the compiler increasing speed? Have you had any experience with MEX files?
 
No, I don't personally have experience with MEX. But a friend of mine who works in the computer vision lab down the hallway stopped using MEX because he said it was too convoluted and didn't provide the speed boost writing in C normally would.
 
I've never used MEX either, except as a swearword when I get obscure 'Your program has crashed and all your data has been lost because of a broken MEX file', or something to that effect...

Best off writing separate C code, I reckon!
 
Back
Top