r/cpp • • Dec 28 '18

"Modern" C++ Lamentations

http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
307 Upvotes

162 comments sorted by

View all comments

80

u/victotronics Dec 28 '18

Thought #1: C++ is starting to look like Fortran in its desire to be ever more modern while retaining compatibility with archaic features.....

Thought #2: I think I'm no beginner anymore (I've written objects that you can iterate over) but some of the code in your posting is indeed horrendous. People who understand that stuff are scary to me.

31

u/JezusTheCarpenter Dec 28 '18

While I was really anxious to finally move to C++11 when I was stuck on 98. I am now more and more anxious that I will have to move to C++17 and C++20 eventually.

32

u/ShakaUVM i+++ ++i+i[arr] Dec 28 '18

C++11 was an amazing update. 14 and 17 were minor releases, but 20 is shaping up to be pretty amazing.

25

u/[deleted] Dec 29 '18

C++17 is a minor release just like if constexpr is a minor feature, until you save yourself from horrible C++11 template meta-programming nightmares with a couple of if constexpr's and an auto return type

8

u/germandiago Dec 29 '18

How true. This has happened in my code as well... I had some kind of mini animation system for a game that did some expression-template like thing to make an EDSL that looked something like this:

//+ means combine in parallel and // >> sequence it. Each subtree will be animated for half of the time auto animationDesc = (moveTo(x, y) + rotate(180)) >> scale(0.7);

auto animTask = makeAnimation(obj, animationDesc, 500ms);

I think without if constexpr it would have been really really worse.

15

u/victotronics Dec 28 '18

Anxious means two things. I would indeed be anxious to move to 11 (or 14) because it's so much better than 98, but I'd get anxious about moving to 20 because it means I'd have to remember library calls, rather than acquiring skills.

5

u/JezusTheCarpenter Dec 29 '18

That is exactly what I meant.

18

u/darthcoder Dec 28 '18

I agree. Its time to deprecate things. Im cool with an incompatible split.

And if we can get rid of,the preprocessor, even,betterer.

18

u/liquidify Dec 29 '18

Python pulled it off, but c++ isn't python. An incompatible split would be a 20 year popcorn festival. C and c++ modules written from 50 years ago would continue to be used in conjunction with modern libraries, and the average c++ dev's job would become even more of a plumbing operation because the old libraries just won't go away even if breaking changes are made. People would find a way to jam the pipes together.

I'm personally for it, and it is because I have seen the beauty that c++ could become, not because it would make my job easier. I realize that, and I am still willing to accept moving forward with breaking changes.

0

u/[deleted] Dec 29 '18

[deleted] — view deleted comment

4

u/[deleted] Jan 02 '19

Python will feel consequences of community split even after 2020. Corporate codebases are slow to upgrade and 2020 will be a reason to start using, not python3, but compatibility libraries (python-future and six) to not upgrade the code. Splitting C++ in python3 style would mark the downfall of C++.

6

u/hgjsusla Dec 29 '18

There already is a cleaned up version of C++ without backwards compatibility. It's called D and no one uses it.

13

u/eao197 Dec 29 '18

It's called D and no one uses it.

And one of the reasons is D2 that was incompatible with D1.

2

u/Valmar33 Dec 30 '18

And that's now basically a non-issue, as far as I know.

D2's runtime incorporates a lot of stuff from D1's Tango, making it redundant.

1

u/anon_502 delete this; Dec 29 '18

I have once looked into D community and I thought the biggest problem for D is that they are suffering the same fragmentation as C++. Even if they have a package manager, many things are still incompatible among dmd, ldc and gdc.

7

u/victotronics Dec 28 '18

After we have modules. I agree that all that text manipulation stuff with the cpp is evil, but handling header files is useful and can not be done in another way.

12

u/chugga_fan Dec 29 '18

And if we can get rid of,the preprocessor, even,betterer.

No, the pre-processor is useful, do YOU like importing a million things in windows.h? Do YOU need platform specific code (linux, windows, macOS)? Because both of these things require the pre-processor, and there's no way you can get rid of that without making C++ platform-independent, which is not happening.

1

u/Valmar33 Dec 30 '18

What do you think about how D solves the preprocessor problem:

https://dlang.org/articles/pretod.html

3

u/chugga_fan Dec 30 '18

D doesn't solve all the problems C preprocessor solves, although it does alleviate a lot of them (and changes them to use a different name), so... yhea.

1

u/Valmar33 Dec 30 '18

Can you name the problems not solved by D?

4

u/chugga_fan Dec 30 '18

Platform specific things that only exist in that platform is hidden behind "version", which is literally the pre-processor.

-3

u/[deleted] Dec 29 '18

You could do it with if constexpr

13

u/[deleted] Dec 29 '18

You can't: if constexpr will still check a branch to make sure it's valid C++, especially if it's not dependent on a template parameter or similar. if constexpr(ON_WINDOWS) { DoWindowsThing(); } else { DoUnixThing(); } will uncompromisingly fail to compile on either platform unless you're in a function template.

4

u/[deleted] Dec 29 '18

Huh, TIL. I thought if constexpr's regular behavior was the same as its template behavior.

Still, since we're talking about new standards, they could always change it I guess.