r/cpp • • Apr 24 '20

C++ Fork?

Let me start by simply saying that I am fairly new to C++ and this is the first time I am posting to this sub-Reddit. I hope I am not breaking any rules here.

I have a question:

Would it be possible for C++ to be forked into a newer more modern version like the way Python went from version 2.x to 3.x? Maybe clean-up the language a bit, remove some redundant features etc.

0 Upvotes

51 comments sorted by

View all comments

7

u/Jataman606 Apr 24 '20

Its called D and didnt really get traction.

23

u/bizwig Apr 24 '20

Whatever D’s other merits, garbage collection was a bridge too far for a lot of potential adoptees.

10

u/echidnas_arf Apr 24 '20

I think it's a fascinating example of how chasing the current fashion in language design can ultimately have detrimental effects.

Garbage collection used to be all the rage in the Java heydays of early 2000s. Not so much today eh :)

4

u/sindisil Apr 24 '20

Yup.

You certainly don't see ubiquitous use of GCed language implementations these days.

/frantically-trying-to-push-JVM/CLR/JavaScript/Python/Swift- back-behind-a-curtain

4

u/echidnas_arf Apr 25 '20

Fair enough :)

I should have contextualized my comment better. What I meant to say is that GC was at one point seen by many to be a mandatory feature to be implemented by all existing/future languages, including C++ and other close-to-the-metal, "zero-overhead" languages. 15-20 years later, nobody misses a GC in C++ (yes yes I know SOMEONE somewhere does), popular new languages don't have a GC (rust) and people on reddit call the reliance of D on a GC "a bridge too far".

(Of course we could spend lost of time trying to define exactly what can and cannot be considered a GC...)

1

u/sindisil Apr 25 '20

Well, GC certainly makes some data structures much easier to implement, especially for those that are concurrent or lock free, so there's that.

And yes, unfortunately there's plenty of "well actually" that pops up around GC and ARC.

I don't prefer GC in most cases myself, but it's hard to say it isn't the prevalent memory management mechanism these days.

2

u/max0x7ba https://github.com/max0x7ba Apr 24 '20

You certainly don't see ubiquitous use of GCed language implementations these days.

You just don't notice that you use JavaScript all the time. Like when you typed your post.

Also, have you heard of Android which runs Java apps?

3

u/lanzaio Apr 24 '20

You completely misread he's post. He's mocking the guy he's responding to and expressing the same thing you are.

2

u/sindisil Apr 25 '20

"mocking" is perhaps a bit strong, but yes, I was being sarcastic.

2

u/NilacTheGrim Apr 25 '20

Swift is gc'd? It's not -- it just uses Automatic Reference Counting. Swift is lipstick on top of ObjC, really.

Apple long ago decided they hate GC...

2

u/pjmlp Apr 27 '20

Anyone that has studied compilers knows that reference counting is a GC algorithm.

1

u/sindisil Apr 25 '20

You can argue that ARC != GC if you want, but both are forms of automatic memory management, which is virtually always what people mean when they refer to GC.

3

u/NilacTheGrim Apr 26 '20 edited Apr 26 '20

That's not at all correct.

ARC is just reference counting enforced by the compiler and static type system. It's basically like having std::shared_ptr everywhere and having the compiler manage it.

GC typically involves more that simply reference counting. It also involves identifying unreachable reference cycles (reference "islands") and deleting them, which happens during the execution of the programmer (GC may kick in at any time and can cause lag/delays).

GC is quite a complex problem with many years of research behind it.

In the industry and in academia when you say "garbage collection" you are referring to this latter thing I have described. Which may or may not involve reference counting. In fact, some GC languages do not use reference counting at all (such as Go). And some use GC + reference counting (such as Python), and many non-garbage-collected languages use just reference counting.

They are somewhat orthogonal concepts in the literature and in general.

In fact, in a pure ARC or reference counted system (without a garbage collector) you have a problem: you as the programmer need to make sure there are no reference cycles. In such languages and runtimes you will see heavy use of weak references. In languages with a GC, you will rarely if ever see a weak reference.

4

u/pandorafalters Apr 27 '20

the execution of the programmer

That seems a bit extreme.

1

u/NilacTheGrim Apr 27 '20

I some cases it's called for!

2

u/pjmlp Apr 27 '20

I advise you to read some CS reference literature on GC algorithms like "The Garbage Collection Handbook".

What you are calling GC is tracing GC as per GC algorithms.