HackerTrans
TopNewTrendsCommentsPastAskShowJobs

DLoupe

no profile record

comments

DLoupe
·8 tháng trước·discuss
I think you missed my point. The problem is not lack of guarding against programmer mistakes. It's that the compiler generates unnecessary code.
DLoupe
·8 tháng trước·discuss
"Another difference in Rust is that values cannot be used after a move, while they simply "should not be used, mostly" in C++"

That's one of my biggest issues with C++ today. Objects that can be moved must support a "my value was moved out" state. So every access to the object usually starts with "if (have-a-value())". It also means that the destructor is called for an object that won't be used anymore.
DLoupe
·10 tháng trước·discuss
and of Even Toned Screens, the halftoning algorithm used by many linux print drivers.
DLoupe
·10 tháng trước·discuss
The compiler generates code for calling the destructor after the object was moved. This was problem #1.

Regarding #2, take Resource Acquisition Is Initialization (RAII) as an example - in RAII, the existence of an object implies the existence of a resource. Now, if you want to be able to move, the object becomes "either the resource exists or it was moved out". As someone else noted in the comments, this affects not only the destructor. Methods cannot assume the existence of the resource, they have to check it first. Kind of like optional<MyResource>.
DLoupe
·10 tháng trước·discuss
> I wonder what you are doing to get yourself in that situation.

The problem with the current move semantics is that, compared to e.g. Rust: 1) the compiler generates unnecessary code and 2) instead of just implementing class T you must implement a kind of optional<T>.

Which means, that after all those years of using smart pointers I find myself ditching them in favor of plain pointers like we did in the 90's.
DLoupe
·10 tháng trước·discuss
By adding syntax and semantics for destructible moves, meaning the moved object is removed from its scope (without calling its destructor.)
DLoupe
·10 tháng trước·discuss
Since I use move semantics all the time, this is for me the most frustrating thing about C++ full stop. I really wish they'd fix this instead of adding all those compile-time features.