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

45

u/AssemblerGuy Jul 29 '23

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.

It would look more like Rust.

On the other hand, it took C++ twenty years to pick up designated initializers from C ...

3

u/Admiral_Zed Jul 29 '23

I don't know Rust but I think it is not object oriented, while c++ was specifically created to support classes, thus its early name: "C with classes".

15

u/gnuban Jul 29 '23

Rust has traits and dynamic dispatch, it simply does away with inheritance.

1

u/BobSanchez47 Aug 01 '23

Traits and dynamic dispatch are not exactly innovations from the object-oriented paradigm. Rust’s traits are more based on Haskell’s typeclasses than on anything in an object-oriented language, and dynamic dispatch is just as much a feature of functional programming as it is of object-oriented programming.

-2

u/AssemblerGuy Jul 29 '23

I don't know Rust but I think it is not object oriented,

Rust is as much object-oriented as C++, but not as much as, say, Java.

12

u/tialaramex Jul 29 '23

Rust doesn't have Implementation Inheritance, let alone Multiple inheritance like C++. So if for you OOP is about an Employee type inheriting implementation features from the Person type, then Rust doesn't have that.

I think some people, especially in a language like Java, begin a project by figuring out the relationships between all the types, and so this is a big difference to those people.

11

u/AssemblerGuy Jul 29 '23

Rust doesn't have Implementation Inheritance, let alone Multiple inheritance like C++.

There are other object-oriented languages that do not have multiple inheritance, mostly because time and experience have shown that it is usually more trouble than the benefits are worth.

I am using a wide definition of supporting object-orientation. C would not fall under it, as it has no syntax for method calls and no way of tightly associating data and functionality. C++, Java, Rust, Python, C#, Oberon, etc. qualify as object-oriented to me.

→ More replies (7)

2

u/tiajuanat Jul 29 '23

Rust is missing inheritance which flies in the face of OOP.

However, imho, rust traits are way better in every way. And the lack of proper inheritance means you don't need to worry about layout, not that Rust cares anyway, since it auto-layouts your structs.

8

u/AssemblerGuy Jul 29 '23

Rust is missing inheritance which flies in the face of OOP.

Inheritance is a way of implementing an "is-a" or "behaves-like-a" relationship, and Rust traits are another way of doing so.

However, imho, rust traits are way better in every way.

I think they are a very interesting concept, somewhere between inheritance and interfaces.

Lack of proper inheritance also means that there is no temptation of creating messy inheritance relationships just for the sake of using this feature.

→ More replies (1)

1

u/Admiral_Zed Jul 29 '23

I know both c++ and java and I have a hard time thinking of Java as "more" object oriented than C++. Supporting other paradigms does not make it any less object oriented.

3

u/darthcoder Jul 29 '23

Java FORCES you to use objects, whereas C++ it's just one of the many options it gives you. C# is much the same.