News for hackers. Stuff that matters.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by logicchains on Friday June 03, 2022 @10:05AM (#31608448)
>Things that are hard in Rust, are even harder in C and C++

This is absolutely not true. Something hard in Rust but almost trivial in C++ (via fold expressions): mapping or folding a function or operator over a tuple of heterogeneous types. E.g. to sum over a tuple of arbitrary numeric types:

    auto mySum = std::apply([](auto... x){ return (x + ...); }, myTuple);
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by crabbygrabby on Friday June 03, 2022 @03:31PM (#31612630)
This is a pretty weird example. Why do you want to sum over a tuple of different data types in the first place? This kind of has a code smell I can't put my finger on...

Fwiw rust doesn't let you dynamically index tuples, because rusts' take on tuples is different.

Should your tuple actually be a struct with a "sum" method on it? Imo probably. Or should you have your numeric types be the same type for better memory layout, maybe...

Just because another language let's you do something doesn't mean you should do it. Kind of like in js, does it make sense to divide a number by a string(not sure if you can do this but guessing it's valid js), probably not, is it a feature or a bug, you decide. Should this be part of say the kotlin standard, probably not.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by Shikadi on Friday June 03, 2022 @01:37PM (#31611337)
Wouldn't this be a nearly identical call, but specifying the add trait? I'm still learning so I'm not sure if I'm missing something