this post was submitted on 31 Jan 2026
220 points (99.1% liked)

Programmer Humor

29100 readers
683 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] XPost3000@lemmy.ml 6 points 1 day ago (1 children)

Yeah this is how it was for me when I first started C++, I was use to any object beyond a simple 3D vector to always be passed by reference

And then I read a C++ book my uncle gave me during a flight and realized that there isn't any syntax for passing a parameter by copy, so obviously that'd have to be the default behavior and I've been passing by reference ever since

[–] Ephera@lemmy.ml 4 points 1 day ago (2 children)

Oh wow, what the hell. I'm not actually familiar with C++ (just with Rust which gets similar reactions with the ampersands), but that's insane that it just copies shit by default. I guess, it comes from a time when people mostly passed primitive data types around the place. But yeah, you won't even notice that you're copying everything, if it just does it automatically.

And by the way, Rust did come up with a third meaning for passing non-references: It transfers the ownership of the object, meaning no copy is made and instead, the object is not anymore allowed to be used in the scope that passed it on.
That's true, except for data types which implement the Copy trait/interface, which is implemented mostly for primitive data types, which do then get treated like C++ apparently treats everything.

[–] KmlSlmk64@lemmy.world 3 points 8 hours ago

There are also the move semantics in C++, which are similar to Rust's ownership transfer, but explicit and with some differences in how the data is actually handled under the hood

[–] zea_64@lemmy.blahaj.zone 3 points 9 hours ago

It probably comes from C, which also copies by default, though it doesn't have copy constructors.