Hello there, fellow programmers! I am an Aeronautical Engineering student who is doing research on Multidisciplinary Optimization (MDO) since the beginning of this year.
All the code I've written so far is in Python, but I want to move it to C so I can learn more about low level programming and so I can have more control over what my code actually does (since it is an MDO code, it needs to be very optimized because every 0.5 seconds added to each iteration add 500 seconds over 1000 iterations (9 minutes!)). I am taking an online course on C from edX, but I still cannot understand how to actually substitute objects for C compliant code.
The main problem is that my original code uses lots of objects, and I simply do not know how to eliminate objects from my code.
Can someone help me? Any help is welcomed.
[edit] Thanks for all your answers, I think I'm getting it now.
Eh, I don't have any specific advice, but the concept of an object and object oriented programming is distinct from classes. You can do OOP in any language. It's just the notion of having specific operations for a type of data and some level of private vs public access. In languages that aren't geared toward that, you need to do most of that stuff yourself.
As a small example regarding methods, in C++, say you had a class that you wanted to have a print method. You make class A and define A.print. Then you can do A a = A(123, 456); a.print().
In C, you use a struct to hold the data, and you define a free function print_A(struct A a), and then call print_A(a). Other than a small syntactic difference, there's little difference between writing a.print() vs print_A(a).
You can arrange the definitions in the headers and C files so that you get something similar to private and public data and functions.
There are similar things for polymorphism, overloading, etc.
I haven't extensively used GTK, but I find that it is a nice C style implementation of object oriented programming, and maybe you could poke around with that to see how they do things.
There’s no native support in C for classes and objects like there is in Python. You can use a struct, which might be enough but there are differences and limitations. Your best bet would probably to find a library in C that builds out support for classes - I can’t give you any recommendations, but I can almost guarantee that a library exists already for that.
It was once said, I think by Alan Perlis, that any programming language that doesn't change the way you think about programming is not worth learning. The other answers are valid in the sense that sometimes OOP is the best solution to a problem even in C, but more to the point you should learn when not to use OOP in the first place.
I'm trying to think of examples here. Maybe you should study the way strings are handled in C, if you're used to object-oriented string handling. C string manipulation is unapologetically non-OO. Also see the way arrays are passed to functions; instead of the array being an object with a size, functions on arrays will take 2 arguments: a pointer to the start of the array, and the array's size. The standard library's binary sort/search functions are also a good reference for how sophisticated C programming is done.