• xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    9
    arrow-down
    1
    ·
    5 months ago

    This graph cuts off early. Once you learn that pointers are a trap for noobs that you should avoid outside really specific circumstances the line crosses zero and goes back into normal land.

    • 5C5C5C@programming.dev
      link
      fedilink
      arrow-up
      10
      ·
      5 months ago

      Your graph also cuts out early. Eventually you want to get performance gains with multi-threading and concurrency, and then the line drops all the way into hell.

        • 5C5C5C@programming.dev
          link
          fedilink
          arrow-up
          4
          arrow-down
          1
          ·
          edit-2
          5 months ago

          I’m not saying you can’t do multi-threading or concurrency in C++. The problem is that it’s far too easy to get data races or deadlocks by making subtle syntactical mistakes that the compiler doesn’t catch. pthreads does nothing to help with that.

          If you don’t need to share any data across threads then sure, everything is easy, but I’ve never seen such a simple use case in my entire professional career.

          All these people talking about “C++ is easy, just don’t use pointers!” must be writing the easiest applications of all time and also producing code that’s so inefficient they’d probably get performance gains by switching to Python.

          • deadcream@sopuli.xyz
            link
            fedilink
            arrow-up
            3
            ·
            5 months ago

            That’s the problem of most general-use languages out there, including “safe” ones like Java or Go. They all require manual synchronization for shared mutable state.

            • 5C5C5C@programming.dev
              link
              fedilink
              arrow-up
              3
              arrow-down
              1
              ·
              edit-2
              5 months ago

              There’s a difference between “You have to decide when to synchronize your state” and “If you make any very small mistake that appears to be perfectly fine in the absence of extremely rigorous scrutiny then this code block will cause a crash or some other incomprehensible undefined behavior 1/10000 times that it gets run, leaving you with no indication of what went wrong or where the problem is.”

          • uis@lemm.ee
            link
            fedilink
            arrow-up
            3
            ·
            5 months ago

            that’s so inefficient they’d probably get performance gains by switching to Python.

            Damn, this goes hard for no reason.

          • uis@lemm.ee
            link
            fedilink
            arrow-up
            1
            ·
            5 months ago

            Well, threadsanitizer catches them in runtime. Not sure about GCC static analyser and other SA tools.

            • 5C5C5C@programming.dev
              link
              fedilink
              arrow-up
              3
              ·
              edit-2
              5 months ago

              I use thread sanitizer and address sanitizer in my CI, and they have certainly helped in some cases, but they don’t catch everything. In fact it’s the cases that they miss which are by far the most subtle instances of undefined behavior of all.

              They also slow down execution so severely that I can’t use them when trying to recreate issues that occur in production.

              • uis@lemm.ee
                link
                fedilink
                arrow-up
                1
                ·
                5 months ago

                They caught lock inversion, that helped to fix obscure hangs, that I couldn’t reproduce on my machine, but were constantly happening on machine with more cores.

    • Pelicanen@sopuli.xyz
      link
      fedilink
      arrow-up
      6
      ·
      5 months ago

      C++ is unironically my favorite language, especially coding in python feels so ambiguous and you need to take care of so many special cases that just wouldn’t even exist in C++.

        • Narwhalrus@lemmy.world
          link
          fedilink
          arrow-up
          6
          ·
          5 months ago

          Typically, I can read an “average” open source programmers code. One of the issues I have with C++ is the standard library source seems to be completely incomprehensible.

          I recently started learning rust, and the idea of being able to look at the standard library source to understand something without having to travel through 10 layers of abstraction was incredible to me.

          • barsoap@lemm.ee
            link
            fedilink
            arrow-up
            5
            ·
            5 months ago

            One of the issues I have with C++ is the standard library source seems to be completely incomprehensible.

            AAAAAAhhh I once read a Stroustrup quote essentially going “if you understand vectors you understand C++”, thought about that for a second, coming to the conclusion “surely he didn’t mean using them, but implementing them”, then had a quick google, people said llvm’s libc++ was clean, had a look, and noped out of that abomination instantly. For comparison, Rust’s vectors. About the same LOC, yes, but the Rust is like 80% docs and comments.

            • uis@lemm.ee
              link
              fedilink
              arrow-up
              1
              ·
              edit-2
              5 months ago

              I think some of those abominational constructs were for compile-time errors. Inline visibility macro is for reducing bynary size, allowing additional optimizations and improving performance and load time.

              In my projects I set default visibility to hidden.

          • magic_lobster_party@kbin.run
            link
            fedilink
            arrow-up
            2
            ·
            5 months ago

            I wonder what went into their minds when they decided on coding conventions for C++ standard library. Like, what’s up with that weird ass indentation scheme?

        • xmunk@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          5 months ago

          You can absolutely read my code. The ability (similar to functional languages) to override operators like crazy can create extremely expressive code - making everything an operator is another noob trap… but using the feature sparingly is extremely powerful.

    • WormFood@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      5 months ago

      pointers are fine, but when you learn about the preprocessor and templates and 75% of the STL it goes negative again

      c++ templates are such a busted implementation of generics that if I didn’t have context I’d assume they were bad on purpose like malbolge

    • orbitz@lemmy.ca
      link
      fedilink
      arrow-up
      1
      ·
      5 months ago

      First year programming in the late 90s … segmentation fault? I put printfs everywhere. Heh. You’d still get faults before the prints happened, such a pain to debug while learning. Though we weren’t really taught your point of the comment at the time.

      Least that was my experience on an AIX system not sure if that was general or not, the crash before a print I mean.

      • xmunk@sh.itjust.works
        link
        fedilink
        arrow-up
        2
        ·
        5 months ago

        Yea, pointer arithmetic is cute but at this point the compiler can do it better - just type everything correctly and use []… and, whenever possible, pass by reference!

    • lazyneet@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      5 months ago

      I’ve been using C++ almost daily for the past 7 years and I haven’t found a use for shared_ptr, unique_ptr, etc. At what point does one stop being a noob?

      • MajorHavoc@programming.dev
        link
        fedilink
        arrow-up
        4
        ·
        5 months ago

        At what point does one stop being a noob?

        I recognize that trick question. For C++, the answer is always “soon”.

      • AngryPancake@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        arrow-down
        1
        ·
        5 months ago

        Given that you probably are using pointers, and occasionally you are allocating memory, smart pointers handle deallocation for you. And yes, you can do it yourself but it is prone to errors and maybe sometimes you forget a case and memory doesn’t get deallocated and suddenly there is a leak in the program.

        When you’re there, shared_ptr is used when you want to store the pointer in multiple locations, unique_ptr when you only want to have one instance of the pointer (you can move it around though).

        Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).

        • arendjr@programming.dev
          link
          fedilink
          arrow-up
          4
          ·
          5 months ago

          Smart pointers are really really nice, I do recommend getting used to them (and all other features from c++11 forward).

          You’re recommending him to give up his sanity and/or life?

          • porgamrer@programming.dev
            link
            fedilink
            arrow-up
            2
            ·
            5 months ago

            I would have said the same thing a few years ago, but after writing C++ professionally for a while I have to grudgingly admit that most of the new features are very useful for writing simpler code.

            A few are still infuriating though, and I still consider the language an abomination. It has too many awful legacy problems that can never be fixed.

      • riodoro1@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        5 months ago

        This guy probably still uses a char*.

        What have you been using it daily for? arduino development? I’m hoping no company still lives in pre C++17 middle ages.