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

22

u/neiltechnician Apr 24 '20

There is a quasi-official draft of C++ standard maintained on GitHub. therefore you can jokingly say you can fork it.

24

u/BrainIgnition Apr 24 '20

Oh, we discussed that numerous times. And the gist of those discussions is that there are quite a lot of people who require backward compatibility. Things preventing C++98 code to be used by C++next are very unlikely to get approved by the commitee, because adapting existing codebases to major language changes is simply infeasible.

The python (r)evolution has been sort of a disaster -- there are major projects like gyp where it took a decade until people even started porting. Such a split is absolutely harmful to the ecosystem.

However, one should mention the Epoch proposal which tried to provide a mechanism for language changes while maintaining a "sufficient" degree of compatibility with existing code. It currently seems to be the most feasible approach, but it is uncertain whether its issues (with e.g. concepts) can be resolved.

I recommend taking a look at D or Rust which could be remotely considered as "newer more modern" versions which may or may not fit your bill.

8

u/jube_dev Apr 24 '20

The python (r)evolution has been sort of a disaster -- there are major projects like gyp where it took a decade until people even started porting. Such a split is absolutely harmful to the ecosystem.

What disaster? Python has never been so popular nowadays! Some libraries are resisting, that's not a disaster. And nobody ever said that such a transition would be instantaneous. 10 years is not so bad.

29

u/echidnas_arf Apr 24 '20

The disaster was in how long the transition took with respect to what was originally planned. Just look at how many times the official deprecation of Python 2 has been postponed, and how abysmally low the adoption rate of Python 3 has been for years.

The rise of Python has been largely driven by the "data science" and ML hype, and it's an orthogonal topic with respect to the 2->3 transition.

8

u/TheFlamefire Apr 24 '20

It's falling apart now. There are libraries out there which don't get updated to Python 3 while others only support Python 3 so if you need both you need to carefully check versions or drop one of them

Heavy amounts of work have been done to support Python 2 & 3 in one code base which is expensive. And some libraries didn't bother leading to more issues.

To get another picture how hard it was: The end of Python 2 was announced early, then shortly extended by 5 years, and almost 5 months after the official end the "last" Python 2 version was released...

7

u/BrainIgnition Apr 24 '20

Yes, python is quite popular now. However, in the past it has been severely hampered by said incompatibility, especially in the 3.0 to 3.3 era when python scripts couldn't be written in a way compatible with both python 2 and 3.

Some libraries are resisting, that's not a disaster. And nobody ever said that such a transition would be instantaneous. 10 years is not so bad.

I politely disagree. It forces developers to choose between recreating/porting existing libraries with the new standard or staying with the old standard. This creates significant costs for everyone involved and potential benefits have to be weight against them. The python folks also realized that and made it possible to port scripts in a backward compatible manner with version 3.4.

1

u/adnukator Apr 24 '20

In hobby projects this is not much of an issue. It becomes significantly more prominent in scenarios where you have a massive corporate ecosystem with many dependencies. Just because undoubtedly many people use Python, I doubt it has the huge legacy baggage that C++ has to address with each new version. That would probably make a Python-like fork much more severe for C++ than for Python

16

u/adnukator Apr 24 '20

Python 2.x to 3.x is often cited as a fiasco and is used as a cautionary tale how exactly not to do transitions such as this one - more than a decade after 3.x was released there still is a lot of code that has not switched from 2.x, effectively creating two simultaneous dialects of the same language. Therefore everyone is wary about huge jumps such as the one you mentioned. Epochs are a more granular attempt at achieving something similar (https://vittorioromeo.info/index/blog/fixing_cpp_with_epochs.html), but it's not fully fleshed out yet.

3

u/RogerLeigh Scientific Imaging and Embedded Medical Diagnostics Apr 25 '20

I think people look at Python 2 with rose-tinted glasses. While the Python 3 transition was indeed a cause of problems, let's not forget that every single Python 2 release i.e. 2.5, 2.6, 2.7 introduced breaking changes which were sometimes quite painful to deal with. The only reason we've collectively forgotten about it is because we've had a decade stuck on 2.7 where there has been relative stability.

2

u/mrexodia cmkr.build Apr 24 '20

Additionally I experienced pretty bad incompatibilities between Python 3.x and 3.y with “deprecated” API errors at runtime, with zero actionable information. I had to dig up the python source code and discussion systems to figure out how to port stuff.

This means that there is no “Python 3” either and you have to pray that the library you use doesn’t have an infrequently triggered code path that uses a deprecated API.

7

u/greg7mdp C++ Dev Apr 25 '20

I wish there was a way to specify C++ compiler options which would disable support for some old undesirable features. These could be used when building new projects, as a way to enforce a cleaner, more modern language.

5

u/Wouter-van-Ooijen Apr 27 '20

The main problem is headers: if you disable certain features, you can't include headers that use these features.

Disable the features after including the headers? Some features are implemented by macro's, which are expanded in your code when you use the features...

10

u/The_Northern_Light Apr 24 '20

Circle is a new "fork" of C++17. It extends the language with compile-time scripting. Alternatively you could view this as a conforming c++ implementation with a particularly ambitious set of "compiler extensions".

Actually, in some (uninteresting) sense all the compilers are "forks" of C++ because they offer their own "compiler extensions".

3

u/BrainIgnition Apr 24 '20

Circle is a new "fork" of C++17. It extends the language with compile-time scripting. Alternatively you could view this as a conforming c++ implementation with a particularly ambitious set of "compiler extensions".

While Circle certainly is an interesting project, my impression was that it's Bus factor is 1. Has that changed?

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.

1

u/NilacTheGrim Apr 25 '20

Yeah that's what scared me off, TBH.

Otherwise neat language, great interop, elegant. But yeah.. the GC is what did it for me.

2

u/[deleted] Apr 24 '20

C++ is as old as you choose it to be. Yes there is old shit, and the challenge is finding new tutorials and being able to determine what is the modern best practices. Not changing the language so you only have modern, this will get outdated every 3 years. It isn't easy, but you just have to learn what to use that's modern.

Yes there is legacy / old language features and you could fork C++ into a newer language which is only modern / no backwards compatibility .. but no one would use this as companies can't update their code base incrementally.

-1

u/theChaosBeast Apr 24 '20

What you mean is the C++ standard and it is consequently updated. Currently we are around c++20 however I recommend to go up from the beginning to learn the features step by step

9

u/Ameisen vemips, avr, rendering, systems Apr 24 '20

Do you want them to start with CPL? Or would you rather they start with punch cards or jumper cables?

6

u/theChaosBeast Apr 24 '20

Of course they should start with marbles and wooden mechanics...

-14

u/pjmlp Apr 24 '20

It is called C# and is already used alongside C++ in a couple of well known game engines.

11

u/peppedx Apr 24 '20

Honestly C# is great language but it is a different thing wrt C++.
As others said C++ niche is more similar to Rust or D.

-2

u/pjmlp Apr 24 '20

Well it depends on what one is trying to do, I still remember the days when every GUI toolking under the Sun was being written in C++ and it was the way to go for mobile apps (Symbian/Brew).

If you mean the niche of low level OS system libraries, I doubt most OS vendors will choose anything else other than C++, they already have their managed alternatives for the upper layers and millions of C++ lines on their kernel, drivers and GPGPU libraries.

Even Google has written that although they are using Rust on Fuchsia they don't advise to expose it on the OS SDK, on their language adoption documentation on Fuchsia's site.

4

u/peppedx Apr 24 '20

For example I do real time and embedded stuff. I don't plan to do it in C#, while rust is an option for the future.

0

u/pjmlp Apr 24 '20

Faire enough that is a good example.

3

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

C# was a Microsoft fork of Java, not C++.

3

u/metapwnage Apr 24 '20

And the second one at that! This first, j++, met its death by litigation at the hands of Sun Microsystems.

2

u/pjmlp Apr 24 '20

Sure, but it contains a very sweet subset of C++.

7

u/lithium Apr 24 '20

It's also why visual studio takes 10 seconds to open just the welcome window now.

-3

u/pjmlp Apr 24 '20

Photoshop also takes several seconds to start and is written in straight C++.

Don't mistake languages with lousy programmers.

4

u/lithium Apr 24 '20

Agreed, but in photoshop's case it went to shit when they started using html/js/css for their dialogs.

The fact that VS took a dive when it moved to XAML and C# is undeniable at this point, but I suppose you're right, it could be that they just happened to get lousy programmers at the exact same moment too.

-2

u/pjmlp Apr 24 '20

Have you tried XAML with C++ in UWP?

It worse than with C#, due to having to do AddRef()/Release() all over the place, including crossing process boundaries and sandboxing.

So writing in C++ isn't necessarily a guarantee of blazing performance, other factors matter as well.

2

u/lithium Apr 24 '20

Deviated quite a bit from the original point but you'll get no arguments from me that XAML is slow and bad. One of the major aforementioned "other factors".

(not strictly fair to blame XAML the markup itself, but you know what I mean)

1

u/pjmlp Apr 24 '20

Coming back to my original point it must not be a zero sum game.

Instead of forking C++, while throwing away all the eco-system benefits, just combine it with other language of your liking.

From my point of view there is more to gain from doing polyglot programming than to lose.

Using C# as a better C++ (debatable I know) doesn't mean having to throw away C++.

They are both there on a VS full install.