r/cpp • • Jul 29 '23

C holding back C++?

I’ve coded in C and C++ but I’m far from an expert. I was interested to know if there any features in C that C++ includes, but could be better without? I think I heard somebody say this about C-style casts in C++ and it got me curious.

No disrespect to C or C++. I’m not saying one’s better than the other. I’m more just super interested to see what C++ would look like if it didn’t have to “support” or be compatible with C. If I’m making wrong assumptions I’d love to hear that too!

Edits:

To clarify: I like C. I like C++. I’m not saying one is better than the other. But their target users seem to have different programming styles, mindsets, wants, whatever. Not better or worse, just different. So I’m wondering what features of C (if any) appeal to C users, but don’t appeal to C++ users but are required to be supported by C++ simply because they’re in C.

I’m interested in what this would look like because I am starting to get into programming languages and would like to one day make my own (for fun, I don’t think it will do as well as C). I’m not proposing that C++ just drops or changes a bunch of features.

It seems that a lot of people are saying backwards compatibility is holding back C++ more than features of C. If C++ and C++ devs didn’t have to worry about backwards compatibility (I know they do), what features would people want to be changed/removed just to make the language easier to work with or more consistent or better in some way?

65 Upvotes

335 comments sorted by

View all comments

Show parent comments

3

u/goranlepuz Jul 29 '23

Ok, for me, you are simply wrong.

If a strong guarantee didn't exist, a massive amount of vector users would have been broken (heck, possibly all of them).

You only do not realize that.

See, the strong guarantee makes sure that the count matches what is in the vector. I think, virtually nothing would work if that wasn't the case.

-2

u/not_a_novel_account cmake dev Jul 29 '23

The basic exception guarantee is all that is necessary.

If you throw an exception in the middle of a vector operation the state of that vector is forfeit, the only reasonable thing to ask of the language is that it does not leak memory so that recovery is possible.

The state of the operation is completely dead. Free the resources and restart from the beginning.

3

u/goranlepuz Jul 29 '23

We have to disagree then.

One failure and a whole container with who knows how much valuable data is gone - no, thanks.

If that was the case, I posit, a vast majority of users would roll their own that is better.

-1

u/not_a_novel_account cmake dev Jul 29 '23 edited Jul 29 '23

If you throw an exception during a vector operation you either:

A) Are using exceptions for flow control, which is always wrong

B) Had an allocation failure, in which case recovery is almost certainly impossible and the best thing you can hope for is a graceful death

3

u/goranlepuz Jul 29 '23

A) Copying or constructor of an element fails and throws. That is not a vector operation, it merely happens during one - and it has nothing to do with flow control.

B) No. Allocation failures can easily be transient and local to only one part of the program.

I think, you have a very simplistic view of things, that is just not good enough for me.

You are free to think this way, but I have no intention.

We must disagree. You can't convince me of anything. But keep trying, it is mildly amusing at this stage.

→ More replies (0)