Thread: Do you ever feel you want OOP done with the C way of doing things?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    23

    Do you ever feel you want OOP done with the C way of doing things?

    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).
    Last edited by ccafe; 04-13-2020 at 07:03 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you feel...
    By ILoveVectors in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-16-2005, 05:47 AM
  2. I feel.....clean....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-11-2003, 06:46 PM
  3. win xp look&feel
    By aym_7 in forum Windows Programming
    Replies: 9
    Last Post: 05-11-2002, 08:28 PM
  4. I feel sorry for...
    By Betazep in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 11-25-2001, 03:50 AM
  5. I feel sorry for
    By Betazep in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-28-2001, 11:23 PM

Tags for this Thread