←back to thread

128 points RGBCube | 1 comments | | HN request time: 0.22s | source
Show context
loa_in_ ◴[] No.44497772[source]
Automatically deriving Clone is a convenience. You can and should write your own implementation for Clone whenever you need it and automatically derived implementation is insufficient.
replies(3): >>44498124 #>>44499705 #>>44500307 #
josephg ◴[] No.44498124[source]
But this issue makes it confusing & surprising when an automatically derived clone is sufficient and when its not. Its a silly extra rule that you have to memorise.

By the way, this issue also affects all of the other derivable traits in std - including PartialEq, Debug and others. Manually deriving all this stuff - especially Debug - is needless pain. Especially as your structs change and you need to (or forget to) maintain all this stuff.

Elegant software is measured in the number of lines of code you didn't need to write.

replies(4): >>44498182 #>>44498258 #>>44498373 #>>44498385 #
1. atoav ◴[] No.44498258[source]
The same is true for memory allocation. But I do not think it makes sense that everybody has to write memory allocators from scratch because a few special cases require it.