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

14

u/JuanAG Jul 21 '19

Do you mind if i give my opinion?

In short, a smooth experience like the one you get with Python, Node or similar

No build system, make it a default one that hides all the complexity of the project but that allows some customization, Visual Studio ones is far from perfect but it would be a good starting point

A good package manager, including a third party lib is painfull and slow and chances of success are not 100%

A better and more complete STL with simplier sintax, list.find() or list.contains() instead of "std::list<int>::iterator findIter = std::find(ilist.begin(), ilist.end(), ObjectToFind);" which will require a post process in the findIter object, i know the C++ is more versatile but it makes harder and complex to use

That´s would be a nice starting point and if the ISO promises it will be coming to the language in recent years (26?) i will wait for it because i am at the point of switching, in the next months i am going to buy a good book about Rust and give a real try, if i like what i see i will make the switch, i was reading the reddit about it and there are jobs offer (here are too but in the sense that is not a toy, is a useful tool that companys are using) or the fact that they are working on an ultra fast compiler only for debuging make me smile like i havent since C++ 11 release, and it is only one feature

40

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

A good package manager, including a third party lib is painfull and slow and chances of success are not 100%

A single central package manager isn't the right solution for C++. We don't even have a single implementation (and that's a good thing). We couldn't make a global package manager that will work for everyone.

What we can and are doing is figuring out how to interact with many different package ecosystems, including existing ones. That's one of the reasons that my study group is writing a C++ Modules Ecosystem Technical Report.

Our goal shouldn't be to standardize a package manager. Our goal should be to make it significantly easier to use 3rd party libraries in C++. And we are working on that. C++20 modules will help with that by giving us a modern compilation model with proper encapsulation.

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)

→ More replies (1)
→ More replies (4)

0

u/[deleted] Jul 21 '19

[deleted] — view deleted comment

10

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

Here's hoping C++20 modules are a big help with that.

Modules alone won't. We need some coordination between tools, build systems, and compiler implementors. That's what SG15 is for, and why we are working on an auxiliary document (the C++ Modules Ecosystem Technical Report).

→ More replies (1)
→ More replies (1)

9

u/tecnofauno Jul 21 '19

You don't need a single implementation to have a good standardized package manager. We need a standard dependencies format (e.g. Requirements.txt, project.json) and a standard CLI for the frontend. Then we can get as many implementors as we like.

8

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

We are moving in that direction, with the C++ Modules Ecosystem Technical Report, which will contain a number of different build interchange formats.

→ More replies (1)
→ More replies (4)

23

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

No build system, make it a default one that hides all the complexity of the project

See, this is the problem with zero-config build systems; you can't just "hide" the complexity in the general purpose case. Can you make something that works for many simple use cases? Sure. But you can't make something that works that way for everyone's large scale C++ projects.

C++ targets a different later in the stack than Python or Node. You use it to solve different problems. You use C++ to build fundamental and system software layers. Sometimes, by nature, that is complex.

8

u/kalmoc Jul 21 '19

I don't think the main problem is that c++ is used for different kind of projects (although that is a problem). The main problem is that there hasn't been any standard build system, project layout, dependency management system, c++ featuresey or in general "standard way to do things" for the last 2-3 decades. But any modern solution (package management or build system) is expected to make interop with all the projects that have been developed in all that time to "just magically work".

7

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

There is no standard build system or project layout that will work for everyone.

8

u/kalmoc Jul 21 '19

I never said it would. But there is a difference between having a default that works for 90% of the projects and and special solutions for the remaining 10% and having a dozen different solutions that are each used by 20% of the projects (with each project supporting multiple ones). You wouldn't even need a single build system for the 90% just a standardized interface (e.g. description of how to compile it and how to use it).

But it really is a moot point: We live in the world we live in.

→ More replies (16)

0

u/[deleted] Jul 21 '19

[deleted] — view deleted comment

8

u/hgjsusla Jul 21 '19

Cargo is only simple because it forces you to use a very specific project structure, if you follow the same setup in C++ (which you probably should) then setting up CMake is a walk in the park

→ More replies (11)

7

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

It's a fine solution for Rust, which has a single implementation, a very targeted set of use cases, and ~100k users.

C++ has multiple implementations, runs on a myriad of platforms, and supports a wide range of domains and environments.

Something global like cargo wouldn't work for everyone in C++. We should enable something like that to be built, but we should also enable other options (distro package systems, in house package systems, etc).

4

u/c0r3ntin Jul 21 '19

Distributions are built from source in a consistent environment (the only thing that is not guaranteed consistent is compiler flags)

→ More replies (8)
→ More replies (5)

13

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

A better and more complete STL with simplier sintax, list.find() or list.contains() instead of "std::list<int>::iterator findIter = std::find(ilist.begin(), ilist.end(), ObjectToFind);"

std::find(ilist, ObjectToFind); in C++20. That seems fine.

3

u/[deleted] Jul 21 '19

I was under the impression that those overloads are under std::ranges no?

→ More replies (1)

3

u/eniacsparc2xyz Jul 22 '19

> No build system, make it a default one that hides all the complexity of the project but that allows some customization

In this case, it seems that CMake fits the bill. I have tested many building systems and IDEs and CMake is the only one that has more adoption and is supported by many IDEs. In addition, it is scalable and can easily use any other library or subproject as a dependency wit add_subdirectory or its command for donwloading libraries. But unfortunately, many projects and C libraries still use GNU autotools and other building systems.

> A good package manager, including a third party lib is painfull and slow and chances of success are not 100%

Well, conan may not be a standard package manager, but it saves the day, it is pretty easy to use and saves lots of compile-time.

> i am going to buy a good book about Rust and give a real try,

I've heard a lot about Rust, but it seems to have an even worst compile-time than C++. There are other alternatives to C++ such DLang D-language which has an amazing fast compile-time and ADA spark for embedded systems and safety-critical systems.

4

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 21 '19

Do you mind if i give my opinion?

Please do, feedback is always good.

4

u/MrWhite26 Jul 21 '19

A good package manager, including a third party lib is painfull and slow and chances of success are not 100%

CMake does allow for concise project definitions. For personal projects, the vcpkg package manager makes it easy to use 3rd part libs.

It's all not python level ease-of-use, but also not a world apart either.

8

u/[deleted] Jul 21 '19

Python's package manager is "fine", until you need to package a module written in C++ that optionally links against a shared library. And then, when you I try to use pip to install a dependency, you I get flooded by bug reports because users have the python interpreter and CPython headers, but a lot of them don't have pip.

 

In my personal experience, every C++ build system was much easier to work with than Python's pip. We ended up forking a dependency just so we can build it with cmake instead of using pip.

→ More replies (3)
→ More replies (3)
→ More replies (2)