views:

336

answers:

4

So, a long long time ago I used to program procedurally initially with Basic on my first BBC Model B and then a small amount of Pascal at university as well as assembly along the way.

Then along came OO which seemed much more sensible all round and that was all I used with C++, Perl, Java, Ruby.....

Coming back to programming non web stuff after a break of some 8 years or so on the iPhone I've found Objective C really easy to pick up but every now and again have to drop out of Objective C and back to plain old C for low level stuff and that's where it's back to procedural programming again.

What I'm after is a good guide about how to mix Object Orientated and procedural styles, how to do memory management, whether to wrap the procedural parts in object etc. etc.

Also a good basic guide to good procedural style for C would be helpful as I don't even seem to be able to think in procedural terms any more.

A: 

You don't have to think in a procedural way. Wrap all low level things into classes. You can use objective-c++.

Mykola Golubyev
+1  A: 

If it helps, just think of your procedures/functions as static class methods. The scope of your memory references is a little different, but not much. If you limit your functions to only accessing data passed as parameters, it's even easier as you don't have to figure out the symbols.

EDIT: I should clarify that I'm talking in a general way here. I've not done any iPhone development so I can speak to specifics with regard to memory access/management there.

tvanfosson
+1  A: 

My recommendation would be to use object oriented programming as the highest level of organization and procedural programming for implementation. OO is best at defining interfaces, contracts between components, partitioning code into coherent chunks, etc.

When programmers first start learning about objects, there's a tendency to go nuts with objects, making everything in site an object when a simple built-in type would do. Every number becomes a class, then methods proliferate on the classes, just in case they're needed. It can become a form of procrastination, delaying the point at which you finally get down to writing code that does some work.

John D. Cook
+1  A: 

As far as I know, object oriented programming is essentially to keep data and actions on this data tied together.
C++ and Ojective-C provide already baked mechanisms to help you, but you can still manage to do it by yourself.

Many C libraries just bind a structure pointer as the first parameter of OO methods.
You may be able to find more information around this by googling "C object oriented programming".

total