News for hackers. Stuff that matters.
Re:CppCon 2022 by GuB-42 on Saturday September 17, 2022 @11:27AM (#32878287)
I think coding C in C++ in underrated.

C++ has tons of features, many will say "too many", and it accumulates over every revision. C, by comparison, is simple.

But sometimes C is too simple, it is fine for 99% of your needs, but for the extra 1%, you need C++. If that's the case, just write C and compile it with a C++ compiler so you can take that extra feature you need. Just because you are using a modern C++ compiler doesn't mean you should start using RAII, managed pointers, exceptions, and all these things.

Sometimes it makes sense to go full-on "modern C++", but using C++ literally as "C incremented by one" is a use case that shouldn't be dismissed.

Re:CppCon 2022 by oriolid on Saturday September 17, 2022 @11:44AM (#32878425)
Just asking because I'm curious: What are the parts of C++ that you actually use? To me RAII and managed pointers are by far the most useful features in C++, followed by templates (think of them as type safe macros with slightly less horrible syntax, not as generics).
Re:CppCon 2022 by rsaxvc on Saturday September 17, 2022 @12:23PM (#32878747)
Not the commenter but embedded embedded here so my perspective is a little different.

For me, constexpr for resolving complex build-time logic into constants, cleaner type handling for the math library makes it harder to accidentally pull in a 64-bit libm when we only have a 32- it FPU, and templating for sure.

It's pretty easy in C to reach a point where macros of macros is madness but templates calling templates still works with the debugger and is a powerful mechanism for hoisting complexity out of loops. Also works nicely for writing outer loops once in c++ calling a template specialized to either inline assembly or c++.

Managed pointers sometimes but our team seems pretty good with object lifetimes from a C background, and we don't use too much heap anyway.

RTTI and exceptions we often disable to save code space.

RAII is a little tricky without exceptions, we often use it's easy.

Re:CppCon 2022 by oriolid on Sunday September 18, 2022 @05:24PM (#32891631)
Good point about embedded, smart pointers aren't that great when you try to avoid allocating memory at runtime and never free it anyway. RAII is still useful for managing other lifetimes, though. The last time I worked on embedded stuff the compiler we used generated often larger code for constexpr, so we didn't really use it.
Re:CppCon 2022 by intelVISA on Saturday September 17, 2022 @01:50PM (#32879575)
About the same here: RAII > smart pointers > constexpr > templates > coro in that order.
Re:CppCon 2022 by 5636553454654 on Saturday September 17, 2022 @07:14PM (#32882567)
This is similar to me. As far as modern stuff, I'm willing go upto c++20, and I use smart pointers, templates, constexpr, RAII, and STL.

With templates, I use them for generics, but also judiciously to create meta-linguistic abstractions to get around certain limitations of language. For example, I built an ORM using them.

I don't use auto, or lambdas, or even foreach (I use iterators), despite oddly having much more dynamic language experience.

Re:CppCon 2022 by mrits on Saturday September 17, 2022 @11:54AM (#32878512)
C is simple in a similar way that performing surgery is. Scalpel and whiskey can go a long ways if the training is accurate. A bad surgeon could also be overwhelmed by the amount of modern tools and use the wrong one. But a surgeon up to date on best practices and the wisdom of knowing what the instruments designed for is most likely going to have a higher survival rate.
Re:CppCon 2022 by phao on Saturday September 17, 2022 @03:20PM (#32880529)
This, I believe, touches upon the accidental versus essential complexity theme.

I believe people, in general, agree C is too simple of a programming language to actually deal with all the essential complexity of modern software development in various cases.

The actual complaint people have about C++ is that it has too much extra unnecessary accidental complexity due to weird ways features interact.

The analogy of the Surgeon I believe should be adjusted having these two points in mind. Generally speaking, surgeons would agree that "scalpel and whiskey" are too simple of a tool set for doing modern surgery. However, if you take modern surgeon tools and add a bunch of weirdness to them, then surgeons would reject them on the grounds of being more complicated than needed.

> A bad surgeon could also be overwhelmed by the amount of modern tools and use the wrong one.

When this is contrasted with the C++ situation, I believe the comparison would be fair only if all the modern features in C++ had to do with the inherent essential complexity of software development. That is not the case (at all). Expert developers have been talking about how C++ is unnecessarily complicated for ages (before C++03 even; back when things were simpler in terms of weird language feature interactions).

Re:CppCon 2022 by interroboink on Saturday September 17, 2022 @05:46PM (#32881912)
> doesn't mean you should start using RAII

I agree with your overall point, but I feel like RAII is practically the key feature that C++ provides over C (:

Or at any rate, I wouldn't say it is anything to do with "modern C++". It was there from the beginning, and C++'s object lifetime rules are pretty core to the language IMO.

I'm curious, since you phrased it that way: what C++ feature(s) do you tend to reach for first, when moving from C to C++?

Re:CppCon 2022 by Keyframe on Saturday September 17, 2022 @01:38PM (#32879433)
Right, a lot of people do that. One shouldn't keep out of mind though that C isn't really a subset of C++. There are more than a few differences.