• LedgeDrop ( LedgeDrop@lemmy.zip ) 
    link
    fedilink
    arrow-up
    17
    ·
    4 months ago

    C++ is useful for learning object oriented programming: Describing what really happens in constructors and destructors, the pros/cons of reference counting and how it actually works (using std::unique_ptr)

    These are things that most modern languages try to hide/abstract away, but the underlying problems and limitations never go away, but with C++ you’ll have a better understanding of why they happen.

    However, if you go down the rabbit hole of Template Metaprogramming, I agree with the original post: it takes decades to learn and really only useful exploitable in C++.

    • SinTan1729 ( SinTan1729@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      8
      ·
      4 months ago

      I’ve always preferred the functional approach to programming, so OOP never really intrigued me. That’s one of the reasons why I never liked C++ or Java, but instantly fell in love with Rust. It lets me do a lot of functional style programming, while still being somewhat practical. (I’m looking at you, Haskell.)

      • LedgeDrop ( LedgeDrop@lemmy.zip ) 
        link
        fedilink
        arrow-up
        4
        ·
        4 months ago

        I’ve been a long time believer that some problems are better solved via OOP, others through functional programming. The perfect language would be a successful blend of the two.

        Many popular OOP languages are horribly lacking on FP or it looks like an eyesore (golang, python, etc). …and FP languages trying to do OOP are kinda awkwards (see common-lisp).

        I thought Crystal Lang (a statically type checked dialect of Ruby) was going to be the “perfect language”… but the compile time performance and the lack of 3rd party libraries (like an aws SDK) really made it hard to use.

        Hearing what you said about Rust has renewed my hope.

        That said, I did notice that features like Coroutines have been “experimental” for nearly 9 years.

        I hope I’m missing something obvious, but how would you create any sort of heavy-lifting, long running, multi-session daemon/application without having some sort of asynchronous mechanism that goes beyond threading (which is limited to the number of cores the host machine is running).

        edit: cleaned up a few thoughts (prematurely hit submit)

        • SinTan1729 ( SinTan1729@programming.dev ) 
          link
          fedilink
          English
          arrow-up
          4
          ·
          edit-2
          4 months ago

          I don’t think there’s an std-way of doing it, but the Rust ecosystem has this thing where people usually settle around one library. In this case, it is tokio. Afaik, most async stuff is done using tokio. What little async I’ve used, it’s been using tokio or some library like actix-web that uses tokio under the hood.

          Also, side note, I never understood the idea of why golang is ugly. I think it’s fine, except for maybe the repeated if err != nil guards. Those are ugly. I wish it used additive types for error handling.

        • sudo ( sudo@programming.dev ) 
          link
          fedilink
          arrow-up
          2
          ·
          4 months ago

          some problems are better solved via OOP, others through functional programming. The perfect language would be a successful blend of the two.

          That was the entire goal of Scala and I would say Scala both accomplished it and is a worse language for doing so. Some OOP principles are just bad, namely subtyping. Rust genuinely does blend OOP and Functional in a better way. Instead of classes and interfaces with lambdas you have algebraic data types and type classes with for loops.

      • copacetic ( copacetic@discuss.tchncs.de ) 
        link
        fedilink
        English
        arrow-up
        4
        ·
        4 months ago

        Quite a while ago, I wrote this to document my understanding what OOP actually is.

        This sentence at the end is interesting:

        On the other hand it sounds unlikely that there will be a popular language without object-oriented influences some day, so at least minimal syntax-level support is desirable.

        Rust was published like one year later and it can be considered popular by now. Does Rust support OOP via traits? Kind of yes, but so does Haskell with typeclasses.

    • YaBoyMax ( YaBoyMax@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      4
      ·
      4 months ago

      I don’t disagree that the language is a great way to build an understanding of object lifecycles, but in my experience C++ ctors and dtors are also the biggest source of confusing footguns I’ve ever encountered in any programming language.

      Separately, template metaprogramming is a whole different beast. It’s an extremely powerful tool, but to me it also feels like finding the correct incantation to get it to do exactly what you need for more complex scenarios. It can be really fun if you know what you’re doing, but it also tends to make me very upset at the compiler when my incantations are a bit off.

    • I inherited a supposedly finalised “core” handling data, but only booleans were dealt with and I had to code the other ones. It was coded in template metaprogramming (MSVC & gcc 4.8 😨), just thinking about it gives me chills down the spine!

      It’s a bit fascinating (and your normal template problems if you have any will vanish and your loved one will return) but it’s, IMO, not for large projects 😬. Impossible to debug (not every error is caught compile time after all).

      printf was coded like that (with the variadic template “…”), I don’t remember if it was libraries for the old compilers or the new ones… But that’s a fun way of checking it out IMO!