Search code examples
objective-coopprogramming-languages

Mixing procedural and Object oriented programming


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.


Solution

  • 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 sight 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.