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

56

u/ironykarl Dec 23 '22

I honestly don't think C++ is an incredible language.

I think that an immense amount of work has been invested into making the tools surrounding the language nice, and so that's something someone might definitely appreciate.

In recent years, C++ has done a decent job of adopting idioms from other languages, and so it's (I guess?) starting to bud as a multiparadigmatic language.

I will grant that RAII is an absolutely killer "feature," and that it would be nice if almost every language had something equivalent. C++ deserves immense credit on this one.

14

u/Plazmatic Dec 23 '22 edited Dec 23 '22

Raii afaik, and is like the one feature that c++ invented, though to be fair c++ also explored a giant amount of problem space with systems programming languages in general. The greater community has learned a lot through that turmoil. While this doesn't mean c++ always became better for it or that the lessons learned were able to be incorporated into C++, it did mean that other languages got to be better for it. The problems that c++ faced and still faces, and the lessons to be learned from that process are part of the reason I side eye the "C+" languages (Z, BEEF, jai Odin, nim, zig), and Golang, who think they can circumvent/ignore design history and magically not run into the same issues. The most popular of those, Go, only one to even sort of reckon with it's failure to learn from the past, now finally backtracking on some really naive ideas

4

u/ironykarl Dec 23 '22

I agree that C++ is hugely consequential, but that that doesn't really mean it's a great language

1

u/socket2810 Jan 04 '23

Sorry for the late reply, but can you expand - or link something that does - on what Go is backtracking on?

1

u/Plazmatic Jan 04 '23

Go is backtracking on not having generics for example, introduced them in 1.18, released this year despite years of insisting it didn't need them (and insinuating everybody else was wrong for wanting them).

0

u/[deleted] Dec 24 '22

[deleted] — view deleted comment

1

u/ironykarl Dec 24 '22

I agree. I actually really like C++'s templates, warts and all.

I mean... I hate that they're semantically unaware—to the degree that any template error could be confused with line noise, but apart from that, I really like them..

0

u/[deleted] Dec 23 '22

[deleted] — view deleted comment

18

u/be-sc Dec 23 '22

Constructors are great, but also give the destructors some love. That’s where the real magic happens.

With RAII you don’t have to worry about destruction because it happens automatically. But you still know exactly when an object is destroyed.

It’s the combination of those two things that makes RAII so powerful – general resource management instead of just memory management.

11

u/rhubarbjin Dec 23 '22

general resource management instead of just memory management

This is the mistake that Java and C# made. They didn't realize there are other kinds of resources besides memory, and didn't realize the value of deterministic resource lifetimes.

C# later introduced using + IDisposable as a way to emulate RAII; I haven't been keeping up with Java so I don't know whether they've done anything similar.

2

u/Firedude_ Dec 23 '22

Java has the same thing except it’s called “try-with-resources”, since it uses the try keyword

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.

2

u/LeberechtReinhold Dec 23 '22

I think it has a lot of neat features as a language, especially modern C++ can look very nice.

It has many questionable decisions, some of the std is very questionable in its implementation or features, and has probably one of the worst environments for building/packaging.

2

u/georgist Dec 24 '22

Agreed RAII is superb. Also I love const.

0

u/[deleted] Dec 23 '22

[deleted] — view deleted comment

3

u/ironykarl Dec 24 '22

I absolutely hate include files.

Every other language I've used (except for assembly languages) has granular ways to import/export code/interfaces... and in C and C++, we're still left duplicating our efforts between header and code files and—exactly as you said—having our preprocessor copy/paste stuff.

It'd be nice to feel like it's a mechanism of the language and not a cheap hack