C++ Modules: Getting Started Today - Andreas Weis - CppCon 2023

  Рет қаралды 18,430

CppCon

CppCon

Күн бұрын

cppcon.org/
---
C++ Modules: Getting Started Today - Andreas Weis - CppCon 2023
github.com/CppCon/CppCon2023
Modules have been one of the most highly anticipated features of C++20. Unfortunately, it was also the language feature that took the longest to become widely available for developers to use. This year, for the first time, we see broad support for the feature in all major compilers and mainstream build system support through CMake. The goal of this talk is to provide you with all the basic knowledge to allow you getting started with C++20 modules today.
We will take a look at how modules change the build process and why it took so long to implement them. We will take a tour of the essentials of the named modules mechanism and explore the new best practices for physical code structure in a modules-based code base, including how to set up a build with CMake. And last but not least, we will discuss different options for interacting with existing header-based code.
The talk will focus above all else on practicality: We will only be covering features that are widely available for use today with the latest compilers and build tools. We will give special attention to the areas where the design practices for modules differ from the familiar header-based approach and address common misconceptions and pitfalls that are typical among developers first encountering the feature. No prior knowledge of modules is required.
---
Andreas Weis
Andreas Weis has been writing C++ code in many different domains, from real-time graphics, to distributed applications, to embedded systems. As a library writer by nature, he enjoys writing portable code and exposing complex functionalities through simple, richly-typed interfaces. Both of which C++ allows him to do extensively. Andreas is also one of the co-organizers of the Munich C++ User Group, which allows him to share this passion with others on a regular basis.
He currently works for Woven by Toyota, where he focuses on building modern software for use in safety critical systems.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
KZbin Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
---
Registration for CppCon: cppcon.org/registration/
#cppcon #cppprogramming #cpp

Пікірлер: 60
@vesk4000
@vesk4000 5 ай бұрын
Awesome! I've been looking for a good first talk on modules and in particular what I can do right now. The standard is very nice, but it seems a lot of module features haven't been implemented yet, which makes it quite annoying when I watch a lot of talks, they don't take that into account.
@davidsicilia5316
@davidsicilia5316 5 ай бұрын
The best talk on modules thus far at CppCon
@ComicSansMS
@ComicSansMS 5 ай бұрын
A small error on the slides: The CMake FILE_SET for modules sources is called CXX_MODULES, not MODULES. Also, on slide #20 about interface partitions, the names of the module in the primary module interface and the partitions need to be consistent (either all 'm' or all 'mice', but not a mixture of the two).
@Zex-4729
@Zex-4729 4 ай бұрын
Thanks for the talk! So far the best source of explanation for modules.
@christiandaley120
@christiandaley120 2 ай бұрын
Great talk, the include guard trick is genius!
@MathewBensonCodes
@MathewBensonCodes 5 ай бұрын
Happy to have learnt through this talk how to export templates. I was putting the export on the function "part" and couldn't figure out why it wasn't working.
@lucasbraune
@lucasbraune 5 ай бұрын
Great talk!
@theo-dr2dz
@theo-dr2dz 3 ай бұрын
At this time (version 17.8.6) Visual Studio can with no problem have modules that wrap header files that include the C standard library. So, no problem if you write a module that uses a C library. That's already a big deal. It won't work if you include a header that includes the C++ standard library. So if you try to wrap a C++ library that won't work because the library will include stuff from the C++ standard library and you will get name clashes. So, the solution is to have an immediate wrapper module that just includes all standard library headers that are used by the wrapped library in the bit between module; and export module x;. and then exports the library. In most cases that will probably approach most of the C++ standard library. At least it's a trick that works (I verified with a minimal example). Hopefully this issue will be resolved and the trick will no longer be needed soon.
@zahash1045
@zahash1045 5 ай бұрын
this reminds me of a helmet that i had that had a hammer attached to it. So everytime i want to nail something to the wall, i would wear that helmet and swing my head around to hit the nail. but sometimes i miss and i hit my head against the wall instead. So to solve that problem, i added some padding to my forehead. now everything works like a charm.
@kobe4460
@kobe4460 3 күн бұрын
Another fellow jonathan blow watcher
@tiagocerqueira9459
@tiagocerqueira9459 5 ай бұрын
Only C++ can take a concept this simple and make it hard
@indiesigi7807
@indiesigi7807 5 ай бұрын
Contrary to pop opinion the header system is extremely good and won't be replaced any time soon.
@wumi2419
@wumi2419 5 ай бұрын
Does it mean only C++ has real world use then? Since that's one of properties of reality, it makes simple concepts hard by virtue of nuance.
@iliasalaur
@iliasalaur 5 ай бұрын
What is so hard about it?
@llothar68
@llothar68 5 ай бұрын
@@indiesigi7807 I want to keep headers too, but make the classes open so i can extend them in private source files. That would be better and simpler.
@llothar68
@llothar68 5 ай бұрын
@@iliasalaur They didn't try to work against the root of all this problems. Single translation units. A 1970s concept that is so wrong. We could have so much nice things if we could get of command line compilers and obj files, instead go with a server that get feed c++ source files and spits out executables. Thats the solution for the speed problem. The better abstraction could be solved by allowing open classes. Objective-C++ is doing it very well but only for the Objective-C.object model.
@victoreijkhout7115
@victoreijkhout7115 5 ай бұрын
Is 17:53 correct? My compiler thinks that the implementaiton module is trying to import itself. Oh wait, the code is correct but the compilation order is crucial, as was not mentioned. 21:29 should the "m:" twice be "mice:"?
@ComicSansMS
@ComicSansMS 5 ай бұрын
Yes, the 'm:' on slide 20 was a typo and should be 'mice:'. Thanks for catching that!
@abdulshabazz8597
@abdulshabazz8597 5 ай бұрын
// File: my_module.p1.cpp export module mice:pinky; export void narf() {}; // File: my_module.p2.cpp export module mice:the_brain; export void take_over_the_world() {}; struct SecretMasterPlan {}; . .
@Fetrovsky
@Fetrovsky 3 ай бұрын
In my_module_p{1,2}.cpp, you have "export module m:something;"... what is m? I don't see you declaring a module called m. Should it be mice instead?
@evgenii_g
@evgenii_g 2 ай бұрын
yep, should be `mice`, not `m`. It's a compile err with `m` otherwise
@kiddkai
@kiddkai 5 ай бұрын
It looks so much complex than the other languages module systems...
@GregWhiteley
@GregWhiteley 5 ай бұрын
Only if you compare it with single vendor programming languages - rust, swift,... - that mandate (and provide) the build system. For those of us in embedded and system programming world we can't rely on those languages. We need C/C++ because it integrates with our systems, not finding a way to get those single vendors to care enough to support our system. Complexity is the price we pay for flexibility, but in return we can ship product.
@jawad9757
@jawad9757 4 ай бұрын
@@GregWhiteley you don't have to use cargo with rust
@_ironrose
@_ironrose 2 ай бұрын
c++ has to be complex i guess
@007LvB
@007LvB Ай бұрын
@@_ironrose Unfortunately yes. But we must remember that C++ is the only language out there that does not force programmers to write their software in any specific way. All C++ does is give us a set of tools and some loose guidelines. Rust assumes programmers can't be trusted and so places as many restrictions as possible. C++ is getting better, sure, but due to legacy reasons it has a lot of "catching up" to do. Modules make C++ almost infinitely better.
@frenchmarty7446
@frenchmarty7446 7 күн бұрын
Welcome to C++.
@PaulMetalhero
@PaulMetalhero 5 ай бұрын
So .bmi files behave like small static libraries?
@szaszm_
@szaszm_ 5 ай бұрын
To me it sounds like the same thing as headers, but in binary format, for the compiler, so it's faster to parse and use.
@spaxio
@spaxio 5 ай бұрын
No, like small per-compiled headers
@olafschluter706
@olafschluter706 5 ай бұрын
Aside of CMake (as of 3.28) modules support by toolchains is very lacking. Neither Apple's clang 15.0 nor gcc 13.2 provide a dependency graph for CMake. clang 17.0 works somewhat with CMake (i.e. it configures and builts everything), but then VS Code can't handle dependencies and code completion, neither with the C/C++ plugin nor the clangd plugin. So for the time being it seems we have to wait for the tools to adopt still. "Getting started today"? No way.
@marianwitek403
@marianwitek403 3 ай бұрын
I'm using visual studio and start to learn modules. The thing is there is bad tutorial on the internet. I import std module to other module that is in project which compile to static library (.lib). In that project I'm only using print function from cpp23. The lib file is about 4mb of size when using imported std. If this is normal? All library contining cpp standard library is linked to my library? Second, if I will link my library with other project that make executable file (.exe) and in that project I'm using cpp standard library (import std) ofcourse I' have to use std.ifc interface again but do I have link c++ standard library (.lib) files again? This is very practical information..not only to show how "nice" is write "import std".
@abdulshabazz8597
@abdulshabazz8597 5 ай бұрын
I don't like the fact imports are dumped into the current namespace. Perhaps if it was a bit more python-y in the way of : import B; B.my_import_func(); in lieu of a using declaration would provide a much cleaner namespace .
@tomleeyrc40
@tomleeyrc40 3 күн бұрын
Namespaces help a little in foo.cpp: export module foo; namespace foo { export void fn(){} } in main.cpp import foo; int main() { foo::fn() } This interface only requires that all your modules have a namespace that is the same as the name it uses when calling export.
@sjswitzer1
@sjswitzer1 4 ай бұрын
Shouldn’t CMake treat modules as libraries, or at least be able to do so? (Maybe it can and I missed it?)
@007LvB
@007LvB Ай бұрын
Why would this be a good idea? A module is simply a translation unit. I think the approach of linking several module interface units together into a library is a much better solution. After all, a library may be formed from just a single TU.
@007LvB
@007LvB Ай бұрын
Exporting from module partitions is not a standard. GCC and Clang do not support it, and Clang developers have even said that it might never be supported! I would add a BIG NOTE at slide 20.
@Lalasoth
@Lalasoth 5 ай бұрын
Hmm you must be from the future.. I cannot find a visual studio release later than 17.8.3
@ComicSansMS
@ComicSansMS 5 ай бұрын
Sorry for being imprecise there. The 19.34 is the C++ toolchain version, the number you get when running cl.exe, not the version number of the Visual Studio IDE that you get in the About... window in Visual Studio.
@Lalasoth
@Lalasoth 5 ай бұрын
@@ComicSansMS thanks for clarifying that.
@LeeJordanMusic
@LeeJordanMusic 5 ай бұрын
Great talk, thanks! Some concepts here, like "export import", "export using", and the ability to export a function returning a non-exported type, make me a bit worried for the future of C++. A lot of people already get confused with headers, and this is IMO adding a whole lot of complexity. That doesn't matter for people who know what they're doing, but this just makes it harder to convince large teams / companies to use modern C++.
@lisinsignage
@lisinsignage 4 ай бұрын
Will C++ 2025 reinvent the concept of .def files fir export definitions 😂😂😂
@kl6995
@kl6995 3 ай бұрын
It's too complicated. As a long term C++ dev, I really was hoping that C++ modules would ease my life and the one of my team. It's 2024 and I don't see the benefits of it so much: too verbose, error prone.. it's depressing because we had to set a new modern language in our stack because of my failure to predict what modules would end up like. My fault, but it kills me.
@007LvB
@007LvB Ай бұрын
It will ease your life. At least I think so. Stick to module interface units for declarations and documentation, and module implementation units for definitions. You never need to worry about inclusion hell again. I would say that's a big win.
@Mempler
@Mempler 2 ай бұрын
3 years and still not properly usable. Good language 👍 Gonna stick with C
@007LvB
@007LvB Ай бұрын
Why on earth would you stick with C? That language is close to useless for practical purposes.
@GuillermoH77
@GuillermoH77 4 ай бұрын
Besides complexity, nobody is using it because it is 2024… and still it is not production ready. IMHO, I think that standard body should deprecate this, and try again. Don’t force all C++ community to support yet another mistake.
@007LvB
@007LvB Ай бұрын
Useless perspective! Modules were introduced with C++20, and the standard library is modularized with C++23. It takes time to do this right. The modules proposals have been underway since 2012, don't kid yourself thinking this is easy or simple!
@KX36
@KX36 5 ай бұрын
Modules were such a wasted opportunity to make something good, ended up ugly and overly verbose with so many rules to remember. Nobody will use, like coroutines.
@szaszm_
@szaszm_ 5 ай бұрын
Coroutines are already usable, although there are more libraries needed in the ecosystem. Asio already makes good use of them for async networking. Writing your own coroutine type is much harder, but most people don't need to do that.
@iliasalaur
@iliasalaur 5 ай бұрын
Coroutines is a very different story, because there is a very small number of scenarios, where they could be handy. Modules are exactly the opposite. This is the piece of standard, that must be used everywhere. I hope that in 2-3 years more compilers will add support for them, because you know, headers - suck
@matejplch7524
@matejplch7524 5 ай бұрын
Coroutines are hard to implement, but easy to use. They are not meant to be implemented by everyone, only library implementers will need to do that, and then millions of C++ developers will be able to use them without knowing the implementation details.
@llothar68
@llothar68 5 ай бұрын
@@iliasalaur I love headers. I love them much more then all the languages that mix the implementation with the declarations.The problem is not hte header but the single translation unit compilation speed (and some better implementation hidding). All of it could have been solved much better without this module system they came up with.
@KX36
@KX36 5 ай бұрын
Coroutines have myriad possible uses. I have used coroutines in Unity for a variety of uses. Anywhere you have async code you can use coroutines and they have a simple intuitive syntax there. You shouldn't need a 3rd party library to use what was supposed to be a major feature of the C++20 standard library, but right now you do. C++20 modules tend to be discussed as a replacement for headers, but when you start using them you find that they don't fully replace headers. They seem to be more useful for joining together code at the library level, rather than at the file level. (And of course only your own new libraries because existing libraries probably don't support modules yet.) Within each library you'll probably still #include headers. I think this is hinted at around slide 29/50 when it talks about "regular files". You could use module partitions but partitions and modules in general are just a ton of header style boilerplate with no real benefit over traditional includes.
Super sport🤯
00:15
Lexa_Merin
Рет қаралды 19 МЛН
OMG 😨 Era o tênis dela 🤬
00:19
Polar em português
Рет қаралды 9 МЛН
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 57 МЛН
The Downsides Of C++ | Prime Reacts
21:23
ThePrimeTime
Рет қаралды 124 М.
Can C++ be 10x Simpler & Safer?  - Herb Sutter - CppCon 2022
1:54:00
Let's get comfortable with SFINAE (C++)
35:55
platis.solutions
Рет қаралды 3,5 М.
BETTER Header Files and Preprocessor Debugging
24:26
The Cherno
Рет қаралды 66 М.
Back to Basics: Debugging in Cpp - Greg Law - CppCon 2023
1:00:37
Rust Modules - Explained Like I'm 5
19:59
Let's Get Rusty
Рет қаралды 67 М.
Samsung or iPhone
0:19
rishton vines😇
Рет қаралды 8 МЛН
AMD больше не конкурент для Intel
0:57
ITMania - Сборка ПК
Рет қаралды 456 М.
Эффект Карбонаро и бумажный телефон
1:01
История одного вокалиста
Рет қаралды 2,5 МЛН
Эволюция телефонов!
0:30
ТРЕНДИ ШОРТС
Рет қаралды 6 МЛН
Готовый миниПК от Intel (но от китайцев)
36:25
Ремонтяш
Рет қаралды 455 М.