Originally Posted by
ccafe
Disclaimer: Please don't take this as an anti-C++ rant. It is not. I also beg you read my words with this caution as well: this is not about saying what language is best, but about how to do something within the C paradigm.
I've been writing both C and C++ code for about 25 years now. However, in these last years, I often find myself having this weird feeling: I need object oriented programming, and C++ fits it, but I feel I need OOP done in the way C does things.
Yes, I'm aware of this SO thread about OOP in C, and I'm aware of the book by Axel Shreiner.
There some things in C++ that deviate from my preferences when programming (yes, I admit this is subjective). Some examples are templates, excessive calls to constructors and destructors in arithmetic expressions unless you explicitly take care, having the C++ standard library written from scratch rather than on top of the C runtime, having std::vector as the recommended approach for dynamically sized arrays (and then realizing you miss the C speed), lack of reflection (whenever I want automatic serialization, I want to retrieve all members in a class, so I want reflection --and then you find lots of preprocessor-based libs for emulating it), and some more that I don't remember now... anyway I think it's not a matter of a list of things, but a broader issue: I believe it's about the mindset used for designing the C++ language, that's the thing, because I believe you can have an OOP mindset together with the C design mindset.
Then I look at the book by Axel Shreiner or to other similar efforts, and I exclaim "this is what I want!"... but using a clean and pure syntax rather than preprocessor and code transformation techniques that require a not so clean syntax.
And of course, some very needed features, like redefining the arithmetic operators for your structs/classes, cannot be done with these techniques (well, you can of course implement an addition operator as a function, but you cannot assign the `+` character to it unless you write Cfront again).
And I feel myself wanting to write a new Cfront. But, first, I'm not a compiler expert, and second, I think I should focus in other projects I'm working in (projects that are written in C++ but that I'd prefer to write in my OOP-ready C, so I'm finding myself in the usual "I need the tools I don't have yet" scenario).
Don't you feel like me sometimes? If you do, were you able to find a good solution for OOP in C? (BTW, yes, I know many languages have been created in the last years, but, they tend to deviate from C far more than C++ does... I want pointers, I want the degree of control you have in C).