• one_old_coder@piefed.social
    link
    fedilink
    Français
    arrow-up
    9
    ·
    2 days ago

    I did this in the past except that the constructor would be called Point_new, and the first parameter would be Point *self. The lack of automatic destruction is a bit annoying, but everything else is fine. A few books have been written on that topic too.

  • Jerkface (any/all)@lemmy.ca
    link
    fedilink
    English
    arrow-up
    8
    arrow-down
    1
    ·
    edit-2
    2 days ago

    now show the pointer hell that would be polymorphism in C. my brain segfaulted just thinking about it.

  • Treczoks@lemmy.world
    link
    fedilink
    English
    arrow-up
    6
    ·
    2 days ago

    Anything I built in the last 15 years of working on our companies flagship products is made like this. Everything belonging to one “object” is in one file. “Private” variables are set to “static”.

    • Patrikvo@lemmy.world
      link
      fedilink
      English
      arrow-up
      6
      ·
      2 days ago

      Makes sense. Most “best practices” and “standards” are just someones idea of structure written down.

      • Treczoks@lemmy.world
        link
        fedilink
        English
        arrow-up
        4
        ·
        2 days ago

        And if you follow good standards like MISRA, you can reduce errors and issues even further.

  • bluGill@fedia.io
    link
    fedilink
    arrow-up
    4
    ·
    2 days ago

    I can do anything in any Turing complete language. However some languages provide some nice syntax advantages, or are less error prone. If you are need to do OOP C++ is a better choice than C because the syntax is much better than the mess needed in C. (D or Ada come to mind as better choices than C++ - you might have your own opinion)

  • xep@discuss.online
    link
    fedilink
    English
    arrow-up
    3
    ·
    2 days ago

    In C and C++ the idea is that the programmer only pays for what they use. I’m not saying that it doesn’t cause its own set of issues (strings, for example) but it isn’t bloated.

    Unless you mean the C++ standard, then have at it.

  • lambalicious@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    2
    ·
    2 days ago

    using pointers and allocation instead of just using the struct natively

    I see we are at the point where we are vibecoding programming memes

  • lurch (he/him)@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    5
    ·
    2 days ago

    It’s nice and clean, but it’s not OO.

    One big difference is: You have to pass the “object” as parameter for everything that modifies it. You could use globals, but then you can only have one “object”.

    Still better than undescriptive naming.

    • Wolfizen@pawb.social
      link
      fedilink
      English
      arrow-up
      3
      ·
      2 days ago

      I disagree. I believe this is object oriented and the object is Point.

      You’re right that the syntax looks different. But whether the object is before the function name: obj.fn(p) or after the function name: fn(obj, p) does not change its status as a parameter. It is still required to be present in the invocation in both cases.

      Object oriented isn’t about where the parameters go, it is about how the program is organised and designed.