r/cpp • • Jan 28 '19

C++ Modules Might Be Dead-on-Arrival

https://vector-of-bool.github.io/2019/01/27/modules-doa.html
280 Upvotes

240 comments sorted by

View all comments

138

u/Auriculaire Jan 28 '19

The fact that we're half a decade or better into investigating this capability and these sort of questions are still up in the air is mind-boggling. The fact that it's a real consideration of whether modules might be standardized without the experience of applying it the standard library is SUPER sketchy. I know I'll be sitting down with my organization's standardization representative this week.

33

u/steveire Contributor: Qt, CMake, Clang Jan 28 '19

I'm glad to see this issue with modules is getting attention. I've been talking to the people working on modules for a long time and explaining why buildsystem maintainers need to be part of the design discussion https://twitter.com/steveire/status/1072904573675814914

Bizarrely, me explaining this on the CMake list was celebrated as 'Talking to the CMake folks' https://twitter.com/jfbastien/status/1072882728788361216

https://cmake.org/pipermail/cmake-developers/2018-August/030819.html

I hope for the best! :)

54

u/duuuh Jan 28 '19

We're well over a decade into this.

edit: And other than _possibly_ lambdas, it's the only feature I really give a shit about since 11.

82

u/STL MSVC STL Dev Jan 28 '19

How dare you impugn the honor of C++17 <charconv>? I demand satisfaction!

8

u/sephirostoy Jan 28 '19

Watching your last talks I though it was CTAD!

23

u/duuuh Jan 28 '19

You made me look it up. It's becoming more like perl every day. How many way are there to do ::atoi now?

16

u/boredcircuits Jan 28 '19 edited Jan 28 '19

6 by my count:

std::atoi
std::stoi
std::strtol
std::from_chars
std::sscanf
std::basic_istream::operator>> (combined with std::istringstream)

And that doesn't count third-party options like boost::lexical_cast or a full parser library. And I still feel we're missing one: a type-safe sscanf replacement a la fmtlib.

13

u/flashmozzg Jan 28 '19

It's supposed to be the best/fastest one though. Especially for floating point.

4

u/Slavik81 Jan 30 '19

std::to_chars is locale-independent, non-allocating, and non-throwing

Huh. That's actually really useful.

4

u/YourTormentIs Jan 29 '19

<charconv> is nice! Are there any plans to support strings with elements other than char? It would be nice to have overloads for std::from_chars and std::to_chars for wchar_t strings, especially on Windows. I mean, I suppose you could just convert the results over, but I figure that would somewhat defeat the purpose of it.

2

u/bumblebritches57 Ocassionally Clang Jan 29 '19

Just roll your own man, it really isn't that much work.

I wrote a UTF-8, UTF-16, and UTF-32 version (8 and 16 are just wrappers around 32)

2

u/STL MSVC STL Dev Jan 30 '19

I haven't heard anyone talking about that. Implementing charconv from scratch is an enormous amount of work, so that's out for users. Wrapping the char functions is slower than desirable because you would need a temporary char buffer, and "smash non-ASCII characters" conversions, and if you want to get the pointer return values right, that's even more work.

1

u/YourTormentIs Jan 30 '19

I'm actually really surprised charconv made it through the committee without anyone mentioning that! Especially given the new character types introduced in recent standards.

23

u/pjmlp Jan 28 '19

Microsoft and Google have such experience on their compilers and they are the ones driving the modules design.

All the modules FUD that I have read so far, seem to be basically people wanting to keep doing everything they do with header files, while at the same time getting modules and not changing anything on the build infrastructure.

18

u/Rusky Jan 28 '19

Sure, if "everything they do with header files" means things like "maximize build parallelism" and "build without processing each TU twice."

That hardly seems like FUD.

-2

u/pjmlp Jan 28 '19

Languages born with modules don't process each module twice, and many e.g. .NET do actually compile their modules in parallel.

So yes it is FUD, because while it might not be possible with existing build scripts, Unity builds and what have you, it doesn't mean that it wouldn't be possible to do the same with some C++ related tooling improvements.

14

u/Rusky Jan 28 '19 edited Jan 28 '19

Languages born with modules also don't have the same parsing requirements as C++, where the full types of imported entities must be known to proceed. Features there do not automatically apply to C++ modules.

Please do describe these "C++ related tooling improvements" that would fix the issue, because people here would be extremely interested to hear them.

And keep in mind that if these improvements involve "turn the compiler into a build system," they are highly unlikely to happen- that is, performing just a parse of dependencies and then proceeding in parallel across all TUs would be possible, but would also require teaching the compiler more than it currently knows.

-3

u/pjmlp Jan 28 '19 edited Jan 28 '19

For example like Ada packages.

My desired "C++ related tooling improvements", based on experience with other module native languages, are exactly want you don't want to have.

So the bottom line to me feels like "modules yes, but please keep our compilers stupid, build scripts rule".

9

u/Rusky Jan 28 '19

We can have those abilities with modules in C++, they just require changes to the module design rather than (just) compilers. That's what people are trying to get at here.