• Codex@lemmy.world
    link
    fedilink
    arrow-up
    64
    ·
    1 year ago

    This is why I stick to Rust. The gender affirming surgery takes some getting used to, but at least I have both legs.

  • Tolookah@discuss.tchncs.de
    link
    fedilink
    arrow-up
    36
    ·
    1 year ago

    He forgot to allocate his leg.

    Also, it looks like he pointed to foot correctly. I’m surprised he didn’t shoot his hand, the pointer to a pointer to a foot.

  • observantTrapezium@lemmy.ca
    link
    fedilink
    arrow-up
    29
    ·
    1 year ago

    I’ve heard this trope before but I’m skeptic. I’m not a C expert but I can’t believe memory bugs in that language are so much more benign than in C++.

    • DarkenLM@kbin.social
      link
      fedilink
      arrow-up
      35
      arrow-down
      1
      ·
      edit-2
      1 year ago

      With C, you need to carefully craft your own gun with just iron ingots and a hammer. You will shoot yourself in the foot, but at least you’ll have the knowledge that it was your craftsmanship that led to it.

      With C++, there are already prebuilt guns and tons of modifications that you can combine at will. If you shove it in the right way, you can make a flintlock shoot a 50 cal, but don’t complain when your whole leg gets obliterated.

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      17
      ·
      1 year ago

      It is indeed a trope and a mostly false one - C++ introduces more dramatic ways to footgun yourself but a plethora of tools to make it easier to avoid them - in particular the built in library functions actually encourage good C++ programming practices…

      Well, let’s just ignore gets().

    • aport
      link
      fedilink
      arrow-up
      9
      arrow-down
      2
      ·
      1 year ago

      Memory bugs are only a tiny share of the foot guns in C++

      • MajorHavoc@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        1 year ago

        Yep. Incredibly powerful, and it will not hesitate to help you blow your own legs off.

        The big difference is that git will save your legs in reflog for a couple of weeks.

        • magic_lobster_party@kbin.social
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          Learning about reflog was a game changer. Now I’m never afraid of breaking my branch. If I mess up, I can always git reset —hard to a previous state.

          Another game changer was learning that a perfectly valid way of doing squash is to do git reset to an earlier commit and then do git commit -a. Saves a lot of rebasing headache.

      • AVincentInSpace@pawb.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        1 year ago

        Rust:

        • You find a predefined foot shooting function, but it’s marked as unsafe and someone forgot to document what the safety contract was. You write up an unsafe block anyway and pass that function ownership of a bullet and a mutable reference to your foot, and get a segfault.
        • You search crates.io for “gun” and find a crate called pewpew. It looks incredibly spiffy. It supports semi or automatic fire, being used with or without a turret (or on a user-supplied turret) and with any number of middlewares for storing the bullets and transforming them on their way to the firing chamber. Unfortunately you can’t shoot yourself with it because your foot doesn’t implement the relevant autotraits.

        Systemd:

        • You create a service file for shooting yourself in the foot and set it to run at system startup. It seems to work, but after a cold boot, sometimes your foot has a hole in it and sometimes it doesn’t. After hours of debugging, you discover that this is because sometimes the gun service starts up and fires its bullet at nothing before the foot service finishes initializing and puts itself in the way. To resolve this you will likely need to edit the source code of your foot to make it support systemd-notify.
  • HStone32@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    I don’t want to give the impression of being elitist, nor am I trying to make myself look super skilled, but whenever I hear people criticizing C for being unsafe, or for lacking some library, I can’t help but think that’s a skill issue, not an actual problem with the language.

    • lseif@sopuli.xyz
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      i think its more a critism of using C where it shouldnt, or by people who shouldnt use it. certainly a skill issue, but a lot of people simply will make mistakes, and better to be safe. C of course has its uses though