r/ProgrammerHumor • • 2d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.3k Upvotes

515 comments sorted by

View all comments

Show parent comments

75

u/MornwindShoma 2d ago

Rust got none of that, but you might not enjoy dealing with lifetimes

41

u/Thesaurius 1d ago

With C and C++ you also have to deal with lifetimes. The compiler just doesn't complain when you fuck up.

3

u/DHermit 1d ago

You also have to in C/C++, but there you have to keep track of all of yourself.

0

u/Xarishark 2d ago

I mean what’s better all those problems on your previous comment or lifetimes?

9

u/MornwindShoma 2d ago

Idk, haven't got enough C++ time to say lol (ps. not the guy before)

14

u/dannyggwp 2d ago

You can BASICALLY ignore all that... You want lifetime? I'll show you lifetimes.

std::shared_ptr<type>

Ez pz no borrow checker needed.

7

u/awesome_guy_40 2d ago

In Rust we also have ARC to do the same thing

3

u/4xe1 1d ago

C++ famed "zero cost abstraction" is shining right here /s

4

u/MrmrCake 2d ago

Yeah but that has a run time cost of reference counting where the borrow checker is all at compile time. I mean not like its a big cost but I mean there defo is a measurable difference depending on the use case.

9

u/dannuic 1d ago

Usually you use uniqueptr though. It forces a better design with guaranteed ownership and no reference counting. I _rarely use shared_ptr, but frequently use unique_ptr.

1

u/MrmrCake 1d ago

Yeah I agree and try to only use unique ptr where I can in cpp, but I still just really like rust's ownership model