On the one side I really like c and c++ because they’re fun and have great performance; they don’t feel like your fighting the language and let me feel sort of creative in the way I do things(compared with something like Rust or Swift).

On the other hand, when weighing one’s feelings against the common good, I guess it’s not really a contest. Plus I suspect a lot of my annoyance with languages like rust stems from not being as familiar with the paradigm. What do you all think?

  • mipadaitu@lemmy.world
    link
    fedilink
    English
    arrow-up
    31
    arrow-down
    1
    ·
    9 months ago

    Depends on if you’re coding for critical infrastructure (i.e. - electrical grid), or writing a high performance video game that can run on older hardware.

    We should absolutely have specific licenses like Civil Engineers do for computer infrastructure that is required for any software written for specific purposes. It would be a nightmare to implement, but at some point, it’s going to be needed.

    • SorteKanin@feddit.dk
      link
      fedilink
      arrow-up
      9
      arrow-down
      6
      ·
      9 months ago

      writing a high performance video game that can run on older hardware

      Unless it’s some really exotic platform, I’d honestly still say no. Rust has shown that memory safety and performance doesn’t have to be a tradeoff. You can have both.

      But sure, if whatever you’re targeting doesn’t have a Rust compiler, then of course you have no choice. But those are extremely rare cases these days I’d say.

      • themusicman@lemmy.world
        link
        fedilink
        arrow-up
        7
        arrow-down
        1
        ·
        9 months ago

        There’s always a trade-off. In rust’s case, it’s slow compile times and comparatively slower prototyping. I still make games in rust, but pretending there’s no trade-off involved is wishful thinking

        • Lmaydev@programming.dev
          link
          fedilink
          arrow-up
          3
          arrow-down
          1
          ·
          9 months ago

          They mean a trade off in the resulting application. Compile times mean nothing to the end user.

          • Dave.@aussie.zone
            link
            fedilink
            arrow-up
            1
            ·
            9 months ago

            That may be true but if the language is tough to develop with, then those users won’t get a product made with that language, they’ll get a product made with whatever language is easier / more expedient for the developer. Developer time is money, after all.

      • cm0002@lemmy.world
        link
        fedilink
        arrow-up
        6
        arrow-down
        7
        ·
        edit-2
        9 months ago

        I don’t even think we really need to eek out every MHz or clock cycle of performance these days unless your shipping code for a space vehicle or something (But that’s an entirely different beast)

        We’ve got embedded devices shipping with 1GHz+ processors now

        It’s just time to move on from C/C++, but some people just can’t seem to let go.

        • Croquette@sh.itjust.works
          link
          fedilink
          arrow-up
          4
          ·
          9 months ago

          Because there is still market for small mcus. A 1GHz processor is a lot more expensive than a 32 bits 75MHz. If you produce even a low number of units, the price difference can be huge.

        • pycorax@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          9 months ago

          Battery life is a reason. I’ve had clients come to me complaining their solution from another vendor didn’t last very long. Turns out it was running Java on an embedded device.

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    12
    arrow-down
    6
    ·
    edit-2
    9 months ago

    Leaders in Industry Support White House Call to Address Root Cause of Many of the Worst Cyber Attacks

    And it’s called C/C++. It’s gotten so bad that even the friggin’ white house has to make a press release about it. Think about it, the place where that majority barely even understand the difference between a file browser and a web browser is telling you to stop using C/C++. Hell, even the creator and maintainers of the language don’t know how to make it memory safe. If that isn’t a wake up call, then nothing ever will be.

    And this isn’t the first call! The IEEE also says more clearly: GTFO C/C++.

    If you want memory-safe, don’t write C/C++. Trying to get that shit memory-safe is a hassle and a half. You’re better off learning a language that isn’t full of foot-guns, gotchas, and undefined behavior.

    CC BY-NC-SA 4.0

    • abhibeckert@lemmy.world
      link
      fedilink
      arrow-up
      7
      arrow-down
      5
      ·
      9 months ago

      If you want memory-safe, don’t write C/C++.

      Fixed that for you. There’s no situation where you want buffer overruns.

      • cm0002@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        9 months ago

        There’s no situation where you want buffer overruns.

        I want buffer overruns in my game consoles for jailbreaking purposes lmfaoooooo

  • Faresh@lemmy.ml
    link
    fedilink
    arrow-up
    6
    ·
    9 months ago

    What memory-safe systems programming languages are out there, besides Rust?

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

    C++ can have excellent performance without ever using a single pointer and avoiding unsafe functions like gets() - this isn’t necessarily a judgment on language - it’s a judgement on bad programming habits.

    Pointers fucking suck, in a modern C++ codebase everything should be pass by value or const/mutable ref. To my preference I’d rather drop mutable refs to force everything to be more functional but whatever.

    • OsrsNeedsF2P@lemmy.ml
      link
      fedilink
      arrow-up
      15
      arrow-down
      2
      ·
      9 months ago

      I mean that’s just the problem with C++. There’s 17 different ways to do things, 2 are always wrong, 14 are contextual, and 1 is reserved for super special cases

      • HornyOnMain@kbin.social
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        9 months ago

        And the one you choose is always the one that’s weak to the specific vulnerability you didn’t think of!

    • abhibeckert@lemmy.world
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      edit-2
      9 months ago

      Pointers suck in C++. In other languages every single variable is a pointer and it works perfectly with no memory bugs and great performance.

      Pass by value often uses too much memory. Especially if you have a bunch of simultaneous functions/threads/etc that all need to access the same value at once. You can get away with it when your memory is a few dozen integers, but when you’re working with gigabytes of media… you need pointers. Some of the code I work with has values so large they don’t even fit in RAM at all, let alone two or three copies of them. Pass by value could mean writing a hundred gigabytes to swap.

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

        That’s one reason I mentioned pass by reference “smart” languages will do it automatically depending on the size of the argument, some languages (including my beloved PHP) even have a copy-on-edit functionality where everything is technically passed as a mutable reference but as soon as you mutate it (unless it was explicitly marked as a mutable reference) it will copy the original object and have you edit the copy instead of the original.

        Is being explicit about when copies happen almost always a good thing - yea the overhead of that system is undesirable in performance sensitive situations - but for a high level scripting language it’s quite nice.

    • SorteKanin@feddit.dk
      link
      fedilink
      arrow-up
      10
      arrow-down
      4
      ·
      9 months ago

      Working with habits is just not good enough. C++ has far too many footguns to be considered a safe language and there are frankly objectively better modern alternatives that you should use instead, perhaps except if you have a really large legacy code base you can’t replace (but even then, consider calling into it via FFI from a safe language).

      Even if you tried to actually enforce these habits, you’d just end up inventing a new language and it would be incompatible with previous C++ too.

      C++ is not a viable language for the future.

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

        I get kinda bad vibes from this comment and I’d like to explain why…

        If somebody said “We’re building a point of sale terminal and to make it secure we’re going to be using C++” I’d probably have a dumbfounded expression on my face unless they immediately continued with “because there are libraries we can lean on to minimize the amount of code we need to write.”

        C++ has an extremely mature ecosystem - Qt is essentially it’s own language at this point! There are reasons to still consider building in C++ and saying “C++ is not a language for the future” feels dogmatic and cargo culty to me. Algol, Cobol and Fortran still have programming communities and while I agree that C++ is outsized in presence for the danger it presents there are still good reasons to choose it for some specific domains - high performance graphical programs being one of those in particular.

        C++ has a plethora of foot guns and you need to be aware of them but when you are they’re easy to avoid in fact your quote:

        Even if you tried to actually enforce these habits, you’d just end up inventing a new language and it would be incompatible with previous C++ too.Even if you tried to actually enforce these habits, you’d just end up inventing a new language and it would be incompatible with previous C++ too.

        Is probably the thing I agree most with - well built C++ isn’t incompatible with regular ol’ C++ but it feels like a different language… but as a not too old old-man-developer different projects often feel like different languages - each company/project has tools and libraries they use and it’ll cause code written in the same language to read really differently… I’m a functionally oriented programmer with a pretty particular style, my C++, Python, Java, PHP, Node and Rust all look nearly the same except for language specific peculiarities.

        So yea, discipline is needed and nobody’s default choice should be C++ but if you follow best practices your C++ can be quite safe.

        that all said… I fucking hate the concept of definition files being sseparate from code files so I’m not going to use C++ anytime soon.

  • fubo@lemmy.world
    link
    fedilink
    arrow-up
    10
    arrow-down
    6
    ·
    9 months ago

    Rust does memory-safety in the most manual way possible, by requiring the programmer prove to the compiler that the code is memory-safe. This allows memory-safety with no runtime overhead, but makes the language comparatively difficult to learn and use.

    Garbage-collected compiled languages — including Java, Go, Kotlin, Haskell, or Common Lisp — can provide memory-safety while putting the extra work on the runtime rather than on the programmer. This can impose a small performance penalty but typically makes for a language that’s much easier on the programmer.

    And, of course, in many cases the raw performance of a native-code compiled language is not necessary, and a bytecode interpreter like Python is just fine.

    • SorteKanin@feddit.dk
      link
      fedilink
      arrow-up
      15
      arrow-down
      1
      ·
      9 months ago

      Rust does memory-safety in the most manual way possible

      The most manual way is what C does, which is requiring the programmer to check memory safety by themselves.😛

      Also will say that outside of some corner cases, Rust is really not that harder than Java or Python. Even in the relatively rare cases that you run into lifetimes, you can usually clone your data (not ideal for performance usually but hey its what the GC language would often do anyway). And reliability is far better in Rust as well so you save a lot of time debugging. Compiles = it works most of the time.

      • 520@kbin.social
        link
        fedilink
        arrow-up
        5
        ·
        edit-2
        9 months ago

        The most manual way is what C does, which is requiring the programmer to check memory safety by themselves.😛

        The difference is, Rust will throw a tantrum if you do things in an unsafe way. C/C++ won’t even check. It’ll just chug along.

        Rust is really not that harder than Java or Python.

        As someone who’s done all three, the fuck it isn’t.

        If you are familiar with C/C++ best practices to any operational level, those things will translate over to Rust quite nicely. If not, that learning curve is going to be fucking ridiculous with all the new concepts you have to juggle that you just don’t with either Java or Python.

      • admiralteal@kbin.social
        link
        fedilink
        arrow-up
        6
        arrow-down
        1
        ·
        edit-2
        9 months ago

        I like Rust a lot, philosophically and functionally… but it is WAY harder. Undeniably very hard.

        Just try and do anything with, say, a linked list. It’s mind-boggling how hard it is to make basic things work without just cloning tons of values, using obnoxious patterns like .as_mut(), or having incredibly careful and deliberate patterns of take-ing values, Not to mention the endless use of shit like Boxes that just generates frustrating boilerplate.

        I still think it’s a good language and valuable to learn/use, and it’s incredibly easy to create performant applications in it once you mastered the basics, but christ.

      • tiredofsametab@kbin.run
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        9 months ago

        Software engineer for almost two decades at this point, programming off and on since a kid in the late '80s: Rust is harder. It did seem to get better between versions and maybe it’s easier now, but definitely harder than a lot of what I’ve worked in (which ranges Perl, PHP, C, C++, C#, Java, Groovy/Grails, Rust, js, typescript, various flavors of BASIC, and Go (and probably more I’m forgetting now but didn’t work with much; I’m excluding bash/batch, DB stored procedures (though I worked on a billing system written almost entirely in them), etc.)

        That said, I don’t think it’s a bad thing and of course working in something makes you faster at it, but I do think it’s harder, especially when first learning about (and fighting with) the borrow checker, dealing with lifetimes, etc.

        The availability of libraries, frameworks, tools, and documentation can also have a big impact on how long it takes to make something.

    • abhibeckert@lemmy.world
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      edit-2
      9 months ago

      A better approach is the one Apple uses with Swift (and before that, Objective-C… though that wasn’t memory safe).

      In swift the compiler writes virtually all of your memory management code for you, and you can write a bit of code (or annotate things) for rare edge cases where you need memory management to do something other than the default behaviour.

      There’s no garbage collection, but 99.999% of your code looks exactly like a garbage collected language. And there’s no performance penalty either… in fact it tends to be faster because compiler engineers are better at memory management than run of the mill coders.

    • floofloof@lemmy.ca
      link
      fedilink
      English
      arrow-up
      5
      ·
      edit-2
      9 months ago

      I’m no Rust expert, but in what I have done with it I’ve always found it reassuring to know the compiler has my back, and I haven’t found the rules too onerous. In some ways I prefer this to counting on some black-box garbage collector with unpredictable performance costs, and I certainly prefer catching as many errors as possible at compile time not runtime.