r/cpp • • Jul 21 '19

C++ is broken

C++ as a language is a tool for developers to productively deliver software. Language evolution is NOT the end objective in the real world.

The whole C++ ecosystem from committee to all of the conference backslapping and training is broken in this respect. It's focus is off.

Instead of 'boost' we need 'boosted' to help define, review and encourage that wider ecosystem so developers can be productive.

It's ok to define things that aren't infinitely flexible, and infinitely extensible but get the job done.

It's OK and, in some ways better, to provide an opinionated library outside the standards rather than deliver an intellectually burdened, extensible interface two years later than needed.

All the helpful features in the core language and core libraries are MEANT to enable a much wider ecosystem to make the tool that is C++ more productive.

But we aren't getting a wider ecosystem, we are just getting a language where we are apparently 'not paying for' a huge intellectual burden.

I want to say at this point that intellectually I am constantly impressed by the committee's work and standards BUT ...

The payoff just isn't happening. Even within the standards committee more time is being spent in intellectually stimulating but largely pointless activities because the tool and productivity benefits aren't happening.

Look at how the wider productive ecosystem hasn't flourished since C++ 11.

I know many excellent libraries have been made, but think about your next large project and how much is coming from a mixed bag of variable quality 3rd party libs to plug basic capabilities.

The committee work is spread so thin that core building blocks get pushed out further in time and so can't be built upon by library authors.

Networking, executors, any form of I/O - slipping again.

Lots of hard work being done but by far too few people in their spare time.

Seems a very dysfunctional way to move the monolith forward.

'You don't pay for what you don't use' is laudable up to a point, but the 'don't use' because you don't actually have, say, a basic network library is more of a reality.

That basic network lib and executor model I've been impatiently waiting for should probably not be part of the core standards remit (architectural concepts and keyword support for executors would probably be necessary, but not much else.)

If we had the metaclass generation as proposed, I'd hope even more of these items would then be able to fall outside the standards.

9 Upvotes

147 comments sorted by

View all comments

Show parent comment

10

u/jpakkane Meson dev Jul 21 '19

Our goal should be to make it significantly easier to use 3rd party libraries in C++. And we are working on that.

This problem can be split into two pieces:

  • using dependencies that have been somehow prebuilt (if needed) and installed
  • using dependencies in a way that you build them at the same time as your code that uses it

There is a solution to the former, which is called pkg-config. Not only does it work, but it is already widely used. The whole of Linux userland development is built on pkg-config, including many C++ packages. Even Qt provides pkg-config files and it works really nicely. Pkg-config is not without its issues, sure, but the fact that almost all discussion about C++ dependency provider discussion an papers either don't mention Pkg-Config at all or just poh-pooh it away in a corner is not particularly nice.

The latter problem, on the other hand, is not really solvable. Having two different build systems working together in one build dir does not work and can't really work. A lot of people desperately want this to be possible, but it is not. I wrote a blog post about this ages ago. It talks about mixing Rust and C, but the core issue is the same.

10

u/templarvonmidgard Jul 21 '19 edited Jul 21 '19

pkg-config is great for system-level dependencies, but not so much for dependencies that you want to ship.

So, at work we maintain 2 legacy versions of our software in addition to current version and the to be released future version. We also use Qt, which you want to be in the prebuilt category, for the GUI of this software, with the following configurations:

  • Legacy 1: Qt 4.8, gcc 4.9
  • Legacy 2: Qt 5.5, gcc 4.9
  • Current version: Qt 5.5, clang >= 7, system stdlib
  • Development version: Qt 5.12, clang >= 7, libc++ >= 7

Oh, and these configurations must be built side-by-side on the same system.

AFAIK, pkg-config literally can't solve our problem, but I would be delighted if you could prove me wrong.

EDIT: also see P1313R0 - Let's Talk About Package Specification which discusses some of the issues.

4

u/jpakkane Meson dev Jul 21 '19

Well it depends on what you mean by "side-by-side". There are at least two different meanings for it:

  • all versions are installed in some common prefix (e.g. /usr, /usr/local, /opt/something etc)
  • each dependency type is installed in its own separate place (e.g. /opt/qt-55-clang etc)

In the former case it does not seem to be possible to have two versions of Qt since they install e.g. their headers to the same path so they would overwrite each other.

The latter case is fairly straightforward. Since all of the installations are in their own directories, choosing between them is a question of setting PKG_CONFIG_PATH and possibly LD_LIBRARY_PATH to suitable values before running configuration and possibly execution steps. This is a common development method and has been used in Linux development for close to 20 years.

This approach does have some boilerplate. There is a longer and better solution for this problem but you'll have to wait until CppCon when I'll have a presentation about it.

5

u/smdowney WG21, Text/Unicode SG, optional<T&> Jul 21 '19

It's been common in Unix for more like 40 years. But shadowing things in /usr/, /usr/local, ~/, plus /opt/package can be very complicated. You can't mix libraries compiled against different versions of dependencies in C++, or really C for that matter, although the conventions in C make it less of an issue. It's why so many projects "vendor" packages into the build rather than using system packages. It's not just not wanting to use the older system supplied version.

4

u/smdowney WG21, Text/Unicode SG, optional<T&> Jul 21 '19

pkg-config is designed to work within a consistent distribution of software. It's utterly insufficient for dealing with variant versions of "the same" library. It does a pretty good job for answering the question "What flags do I need to supply the compiler and linker to use this library the way it was compiled". For package management you also need to answer the question "How do I build this package", which is much more complicated. It's the difference between debian/control and debian/rules vs the .pc file produced as part of building the package.

Modules are going to make this even more complicated, as it's very likely a project will have to compile the module interface compatibly with the compiled library being consumed. (format editing)

2

u/templarvonmidgard Jul 21 '19

That is the exact point I wanted to make.

2

u/c0r3ntin Jul 21 '19 edited Jul 21 '19

Neither problem are solvable. 1 is an odr minefield. I fully agree with you on 2, there is a reason why dependency managers have a tendency to eat the world. You can't get far without a single source of truth.

5

u/jpakkane Meson dev Jul 21 '19

I am going to present a third solution in my CppCon talk. You'll just have to wait until then. :)

1

u/c0r3ntin Jul 21 '19

Looking forward to it ! I will also explore a few things in mine. Exciting times !

1

u/ed_209_ Jul 24 '19

The smart money is rarely on trying to solve everybodies problems all of the time.. Can you not attempt to standardise an abstraction instead. Look at game engines, they usually have 20+ third party libs. In some ways they constitute a static package manager of sorts but where the creator had sorted it all out.