CppCon 2019 has ended
Back To Schedule
Thursday, September 19 • 09:00 - 10:00
Are We Macro-free Yet?

Log in to save this to your schedule, view media, leave feedback and see who's attending!

What do you do when an API or even a toolchain is not available in some of your build configurations? #ifdef? When we are talking about writing modern C++, we may have forgotten that code involving preprocessor is not even in C++. We all learned that macros are bad, but very often, when we rely on them by ourselves, we rationalize it, and they became "inexpensive," "necessary," and sometimes "maintainable." After ripping out the last macro introduced in a proprietary C++17 codebase, I concluded that none of these are true if you were introduced to a design without macros.

This talk starts from one of the most demanded and least maintainable use cases of macros, conditional compilation, shows how not to introduce macros from the build system, and discusses the macro-free practice's impact on design and testing. And then, we expand the topic to other areas where we have macros to eliminate, such as logging and metadata macros, discuss the motivations and solutions given C++20. We will finish the talk with advice about what are the macros you want to avoid when we are moving towards a macro-free future.

avatar for Zhihao Yuan

Zhihao Yuan

R&D Software Engineer, Broadcom Inc.
Zhihao Yuan is an R&D Software Engineer at Symantec, a division of Broadcom. He participated in standardizing designated initializers and improved narrowing conversions in C++20 but ends up almost exclusively programmed in Python last year and only recently picked up C++14 again... Read More →

Thursday September 19, 2019 09:00 - 10:00 MDT
Summit 4/5