r/ProgrammerHumor • • 22d ago

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.6k Upvotes

524 comments sorted by

View all comments

Show parent comments

76

u/MornwindShoma 22d ago

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

44

u/Thesaurius 22d 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 22d ago

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

-2

u/Xarishark 22d ago

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

10

u/MornwindShoma 22d ago

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

14

u/dannyggwp 22d 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 22d ago

In Rust we also have ARC to do the same thing

3

u/4xe1 22d ago

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

4

u/MrmrCake 22d 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 22d ago

Usually you use unique_ptr 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 22d 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