Live data from Hacker News

Nobody Understands C++: Intro (2007)

articles.emptycrate.com

11–20 of 53 posts

Re: Nobody Understands C++: Intro (2007)

#11

> The comment in question begins “My take on C++ is that the best programs only use a fraction of the features.” The commenter further states that he is weary of operator overloading and templates. > In my experience, people who make comments like the above tend to be people who think they are C++ experts but who are actually only novices. I do not know the commenter personally, so I’m not trying to say anything abou…

I went from "c++ fondness" to "c++ distaste" over the years. The newest c++ standards fix a lot of issues, but at the same time increase complexity. The backwards-compatibility nature is the classic double-edged sword. If we could avoid it, c++ would be at least significantly nicer (not really less complex).

That being said, a good team using a dab of c++ will beat "high quality C" any time of the year for me. Getting away from the preprocessor alone is huuuuuuuge. Everybody complains about memory safety, and the truth is that with even the dumbest string/buffer class it's actually pretty trivial to do the right thing. c++ _does_ really fix most of the c issues IMHO.

A big problem IMHO is that we "learned" to use c++ properly late. The newest standard revisions came late. The feature abuse it receives is still somewhat rampant, and yes a newcomer to c++ would probably find a use for every single feature in a simple usage scenario.

Reading large c++ codebases is hard due to the intermixing of old/new and simply different styles. It has a huge cognitive load, and that is my primary reason for the growing distaste: I want code to be clear and coherent. I can take the complexity if that's used consistently, but it can change massively between even just PARTS of a project.

Re: Nobody Understands C++: Intro (2007)

#12

TBH, C++ has changed so much that any opinion from 2007 isn't worth much today, and that applies no matter if you think C++ got better or worse since then ;)

Agree, and I suspect that a lot of things will also be deprecated by 2030 once modules get really integrated in the ecosystem.

Re: Nobody Understands C++: Intro (2007)

#13
I won't argue that the first example is cleaner, but both seemingly simple examples have a major issue. Lifetime.

The observer pattern is notorious for being overly complicated in C++ because you have to ensure Observer and Observable keep valid references to each other.

"Modern C++" (what ever that is nowadays) leverages RAII (i.e. scope-based resource management) to improve upon the situation.

With your typical observer (i.e. signal/slots) library you get a "scoped connection" object when registering the callback function. You store that object in your class and when it is destroyed, it breaks the connection. Furthermore, it facilitates the implementation of correct copy and move semantics.

It's not that people don't "understand" C++, the problem is that there are so so many things to watch out for, even in simple use-cases, that even experienced C++ programmers make mistakes on a regular basis.

Re: Nobody Understands C++: Intro (2007)

#14
> A fellow Slashdot poster has unknowingly made my point for me quite well, and it is what I will use to start this intro. The comment in question begins “My take on C++ is that the best programs only use a fraction of the features.”

Plot twist, that Slashdot poster was John Carmack

Re: Nobody Understands C++: Intro (2007)

#15
C++ is very frightened of breaking existing code, including at the binary level. Some shared library built in 2007 stands a decent chance of running today if it avoided the ABI break of ruin and disaster where string and list changed slightly.

It's also widely considered a very complicated language and there's some worry it suffers in user acquisition as a result.

If you take those two properties together, the game plan of making the language look nicer without changing how it works is about all you've got. It accretes more stuff with a bias towards making some use case look nicer.

It leaves margin for faster code below it because slow choices are forever. More syntax over the same operations is a dubious interpretation of making things simpler.

Yet it lives on. People start new projects in it. Some people think the economics work out in favour.

Oh, and some people did understand it in 2007. Maybe only five but they did exist. Some of those may still be heavily involved enough to understand the current language, but I wouldn't be shocked if they're burned out and gone. We might be down to zero.

Re: Nobody Understands C++: Intro (2007)

#16

> The comment in question begins “My take on C++ is that the best programs only use a fraction of the features.” The commenter further states that he is weary of operator overloading and templates. > In my experience, people who make comments like the above tend to be people who think they are C++ experts but who are actually only novices. I do not know the commenter personally, so I’m not trying to say anything abou…

> I realized all this class-ification effort was pure waste, since most of it would never be reused.

I don't think this is a valid take. Classes are not about reuse at all. They are about encapsulation and specifying types/providing interfaces.

> Same with all the idiomatic conversions.

What's your complain about idiomatic conversions?

> Don't get me started on boost.

Why is Boost, or any library at all, relevant in a discussion about C++? Should our opinions on C++ vary if we mention POCO, Abseil, or even Qt?

Frankly, I don't think your personal takes are well informed. It sounds like you struggled to use something different than something you knew expecting that you could simply keep writing the same code in any other programming language, and subsequently started complaining that other languages are not like the one you used. That's hardly a critique of any other language, and instead it's insight on how developers who succumbed to crystallizing their expertise end up suffering from their inability to adapt.

Re: Nobody Understands C++: Intro (2007)

#17

> The comment in question begins “My take on C++ is that the best programs only use a fraction of the features.” The commenter further states that he is weary of operator overloading and templates. > In my experience, people who make comments like the above tend to be people who think they are C++ experts but who are actually only novices. I do not know the commenter personally, so I’m not trying to say anything abou…

I went from "c++ fondness" to "c++ distaste" over the years. The newest c++ standards fix a lot of issues, but at the same time increase complexity. The backwards-compatibility nature is the classic double-edged sword. If we could avoid it, c++ would be at least significantly nicer (not really less complex). That being said, a good team using a dab of c++ will beat "high quality C" any time of the year for me. Gettin…

> It has a huge cognitive load

This. Its like trying to keep three distinct languages (C, old C++, new C++) in one's head at the same time. It is much better use of one's mental energy to spend that effort on three actually distinct languages that are, e.g., tuned to different domains and use cases.

Imho the C++ community needs to address this or eventually become irrelevant as people gravitate to more sane and user-friendly ecosystems. Not sure how that can be done without breaking some eggs. My preference would be for a simplified and streamlined C+++ that tackles this complexity head on.

Re: Nobody Understands C++: Intro (2007)

#18

TBH, C++ has changed so much that any opinion from 2007 isn't worth much today, and that applies no matter if you think C++ got better or worse since then ;)

Today is just tomorrow's yesterday.

I'll just avoid C++ for now, and wait for future articles to say that the C++ of 2023 was too complicated to use.

Re: Nobody Understands C++: Intro (2007)

#19

C++ is very frightened of breaking existing code, including at the binary level. Some shared library built in 2007 stands a decent chance of running today if it avoided the ABI break of ruin and disaster where string and list changed slightly. It's also widely considered a very complicated language and there's some worry it suffers in user acquisition as a result. If you take those two properties together, the game p…

> Some shared library built in 2007 stands a decent chance of running today if it avoided the ABI break of ruin and disaster where string and list changed slightly.

At least with the default standard library implementation on Linux you can still select which version of these classes are used by setting the __GLIBCXX_USE_CXX11_ABI (or something similar) define. Both versions of these classes are still present in the implementation. So the old library can still be used despite that change.

Re: Nobody Understands C++: Intro (2007)

#20

I won't argue that the first example is cleaner, but both seemingly simple examples have a major issue. Lifetime. The observer pattern is notorious for being overly complicated in C++ because you have to ensure Observer and Observable keep valid references to each other. "Modern C++" (what ever that is nowadays) leverages RAII (i.e. scope-based resource management) to improve upon the situation. With your typical obs…

Funny note: Implementing e.g. a flexible observer pattern in Rust has the same ownership and lifetime problems. Usually this involves some weak reference, central broker, etc.

So, that's really not only a language problem, but rather the result of the pattern / data structure involved. I.e. cyclic dependencies not being very nice once you have to think about lifetimes.

Post reply on HN