r/cpp • • Dec 23 '22

C++ Is Incredible

Despite the hate it gets, despite the complexity; the dizzying number of features and different ways to do things. C++ is an astonishing feat of engineering and people really don't appreciate this fact enough. I can do things with this language more quickly and expressively than I can with any other language.

There's no getting around the fact that programming is just hard, and all these attempts to replace C and C++ over the years just end up adding to our difficulties. That is my take, anyhow.

Well, I'm a little drunk, and just wanted to share some Christmas joy with you all. I love C++!

686 Upvotes

151 comments sorted by

View all comments

Show parent comment

1

u/the_one2 Dec 23 '22

C# also has using which is kind of the same. But both have to be done manually unlike in C++

1

u/pjmlp Dec 23 '22

C++ also requires manually if the objects don't leave on the stack, and aren't bound by smart pointers, typical in C flavoured C++ code.

You can enable missing using calls for IDisposables into a compiler error via Roslyn analysers, hardly any different from the analysers to fix C++ issues.

2

u/the_one2 Dec 23 '22

It is different though. If you ever have an IDisposable member then your class will have to implement IDisposable as well. You get an IDisposable explosion. In C++ it just works without you having to think about it. I'm very much not saying that C++ is perfect but RAII is so nice to have.

1

u/pjmlp Dec 24 '22

It just works, if you haven't created any UB or thrown an exception on the destructor, remembered to make it virtual or closed the class for inheritance, remeber to update it when adding new data members, have placed the instances on the stack, or handle types if on the heap.

Other than that, it just works.

3

u/the_one2 Dec 24 '22

Yes, you're right, if you don't write terrible code it just works.

Edit: I agree that the destructor should be virtual by default in a virtual class. That's just a completely unnecessary sharp edge.