• 0 Posts
  • 22 Comments
Joined 2 years ago
cake
Cake day: July 9th, 2023

help-circle
  • There are several ways to achieve an effect equivalent to operator overloading in Rust, depending on exactly how you want the overloading to work.

    The most common is

    fn do_something(arg: impl Into<Args>) {
        ...
    }
    

    This lets you pass in anything into the function that can be converted into the Args type. If you define the Args type yourself then you can also define any conversion that you want, and you can make any construction method you want for it. It’s a small touch more explicit than C++'s operator overloading, but I think it pays off overall because you know exactly what function implementation all different choices of arguments will be funneling into.

    I’ll admit there’s one thing from C++ that I frequently wish were available in Rust: specialization. Generics in Rust aren’t exactly the same as templates in C++ but they’re close enough that the concept of specialization could apply to traits and generics. There is ongoing work to bring specialization into the language, but it’s taking a long time, and one of my projects in particular would seriously benefit from them being available.

    Still, Rust will have specialization support long before C++ has caught up to even a quarter of the benefits that Rust has over it.


  • Even with modern C++ it’s loaded with seg fault and undefined behavior footguns.

    The times when C++ feels more ergonomic than Rust are the times when you’re writing unsafe code and there’s undefined behavior lurking in there, waiting to ambush you once you’ve sent it to production. Code that is 100% guaranteed safe is always, and I really want to emphasize this: always more ergonomic to write in Rust than it is to write in C++.

    Show me any case where C++ code seems more ergonomic than its Rust equivalent, and I will always be able to show you how either the C++ code has a bug hiding in it or how the Rust code can be revised with syntactic sugar to be more ergonomic than the C++.


  • C++ was far and away my favorite language (I used it professionally for 10 years and was always excitedly keeping up with new ISO developments), until I learned the basics of Rust…

    Now it’s my firm belief that the world will become a better place when C++ stops existing. C++ just has no positive role to play in a world where Rust exists at the level of maturity that it already has.

    Whatever they might try to do to C++ to make it less intolerable will be in vain until they’re ready to break backwards compatibility. And once they’re willing to break backwards compatibility to legitimately improve the language, they’re just going to end up with a messy knock off of Rust.








  • I think it’s specifically meant to debunk the idea that meat is the only affordable source of protein-dense food, when in reality there are vegan protein-dense foods that are even more affordable.

    That doesn’t conflict with the fact that a well balanced diet is important; it’s just addressing one sticking point that tends to come up in these conversations.


  • Still much better than C++ templates, and I say that as someone who used to genuinely love C++ template metaprogramming. Admittedly Rust traits+generics are far more limited than C++ templates, but very often I find that to be a positive. The list of things that I feel traits+generics are missing is small and rapidly shrinking.





  • 5C5C5C@programming.devtoProgrammer Humor@programming.devC++
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    10 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.



  • And even if you do get to use pure modern C++ you’ll still get burned by subtle cases of undefined behavior (e.g. you probably haven’t memorized every iterator invalidation rule for every container type) that force you to spend weeks debugging an inexplicable crash that happened in production but can only be recreated in 1/10000 runs of your test suite, but vanishes entirely if you compile in debug mode and try to use gdb.

    And don’t even get me started on multi-threading and concurrency.


  • 5C5C5C@programming.devtoProgrammer Humor@programming.devC++
    link
    fedilink
    arrow-up
    21
    arrow-down
    1
    ·
    edit-2
    10 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.”


  • 5C5C5C@programming.devtoProgrammer Humor@programming.devC++
    link
    fedilink
    arrow-up
    28
    arrow-down
    1
    ·
    edit-2
    10 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.