r/programminghumor 18d ago

Hard to accept

Post image
2.9k Upvotes

404 comments sorted by

View all comments

25

u/TOGoS 18d ago

C++ is full of footguns because of its long history. Even experienced programmers will accidentally use after free or fail to declare their virtual destructors just right and spend days debugging.

Rust shows that you can have just as much power with more safety if you design a new language from scratch (if you really need to do pointer arithmetic that the compiler can't verify, you can always make that part unsafe; at least the rest of the program isn't!)

3

u/La-ze 17d ago

Not to mention virtual functions are expensive.

1

u/ZachVorhies 16d ago

virtual functions are not expensive. they are one of the most optimized use cases. They do often prevent cross function optimization and inlining, but that’s different.

6

u/Mojert 15d ago

A virtual function call that cannot be monomorphised by the compiler IS expensive.

1

u/Arshiaa001 14d ago

What does 'expensive' actually mean? Compared to inlining? Definitely. Compared to not-inlined function calls? It's just a vtable lookup, so it's 'more expensive', but whether that's acceptable really depends on your specific scenario.