• nothacking
    link
    fedilink
    arrow-up
    55
    arrow-down
    6
    ·
    7 months ago

    Hot take, C is better then C++. It really just has one unique footgun, pointers, which can be avoided most of the time. C++ has lots of (smart)pointer related footguns, each with their own rules.

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      17
      ·
      7 months ago

      If you do C, and avoid pointers, do tell me what the point is using the language at all?

      I mean if memory management is “the only way to shoot yourself in the foot” in C, then thats a quite big part of the language!

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

        If you do C, and avoid pointers, do tell me what the point is using the language at all?

        Person is saying that C has one big footgun, while C++ has armory of them

    • MajorHavoc@programming.dev
      link
      fedilink
      arrow-up
      12
      ·
      7 months ago

      Yeah. My journey of love, loathing, hatred, adoration, and mild appreciation for C++, ended with the realization that 90% of the time I can get the job done in C with little hassle, and a consistent, predictable, trustworthy set of unholy abominations.

    • jas0n@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      7 months ago

      Preach brother, I don’t think that’s a hot take at all. I’ve become almost twice as productive since moving from c++ to c. I think I made the change when I was looking into virtual destructors and I was thinking, “at what point am I solving a problem the language is creating?” Another good example of this is move semantics. It’s only a solution to a problem the language invented.

      My hot take: The general fear of pointers needs to die.

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

        I’m not a fan of C++, but move semantics seem very clearly like a solution to a problem that C invented.

        Though to be honest I could live with manual memory management. What I really don’t understand is how anyone can bear to use C after rewriting the same monomorphic collection type for the 20th time.

        • jas0n@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          6 months ago

          Maybe I’m wrong, but aren’t move semantics mostly to aid with smart pointers and move constructors an optimization to avoid copy constructors? Neither of which exist in c.

          I’m not sure what collection type you’re referring to, but most c programmers would probably agree that polymorphism isn’t a good thing.

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

            That’s what std::move does, and you’re right that it’s quite an ugly hack to deal with C++ legacy mistakes that C doesn’t have.

            I say move semantics to refer to the broader concept, which exists to make manual memory management safer and easier to get right. It’s also a core feature of Rust.

            Also I’m talking about parametric polymorphism, not subtype polymorphism. So I mean things like lists, queues and maps which can be specialised for the element type. That’s what I can’t imagine living without.

            • jas0n@lemmy.world
              link
              fedilink
              arrow-up
              2
              ·
              6 months ago

              Hahaha. I knew I was wrong about the polymorphism there. You used big words and I’m a grug c programmer =]

              We use those generic containers in c as well. Just, that we roll our own.

              Move semantics in the general idea of ownership I can see more of a use for.

              I would just emphasize that manual memory management really isn’t nearly as scary as it’s made out to be. So, it’s frustrating to see the ridiculous lengths people go to to avoid it at the expense of everything else.

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

                I definitely agree on the last point. Personally I like languages where I can get the compiler to check a lot more of my reasoning, but I still want to be able to use all the memory management techniques that people use in C.

                I remember Jonathan Blow did a fairly rambling stream of consciousness talk on his criticisms of Rust, and it was largely written off as “old man yells at clouds”, but I tried to make sense of what he was saying and eventually realised he had a lot of good points.

                I think it was this one: https://m.youtube.com/watch?v=4t1K66dMhWk

                • jas0n@lemmy.world
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  edit-2
                  6 months ago

                  Just watched this. Thank you. I think I’d agree with most of what he says there. I like trying languages, and I did try rust. I didn’t like fighting with the compiler, but once I was done fighting the compiler, I was somehow 98% done with the project. It kind of felt like magic in that way. There are lots of great ideas in there, but I didn’t stick with it. A little too much for me in the end. One of my favorite parts C is how simple it is. Like you would never be able to show me a line of C I couldn’t understand.

                  That said, I’ve fallen in love a language called Odin. Odin has a unique take on allocators in general. It actually gives you even more control than C while providing language support for the more basic containers like dynamic arrays and maps.

    • porgamrer@programming.dev
      link
      fedilink
      arrow-up
      1
      arrow-down
      1
      ·
      6 months ago

      The only conceivable way to avoid pointers in C is by using indices into arrays, which have the exact same set of problems that pointers do because array indexing and pointer dereferencing are the same thing. If anything array indexing is slightly worse, because the index doesn’t carry a type.

      Also you’re ignoring a whole host of other problems in C. Most notably unions.

      People say that “you only need to learn pointers”, but that’s not a real thing you can do. It’s like saying it’s easy to write correct brainfuck because the language spec is so small. The exact opposite is true.