Fun with C++26 reflection: Keyword Arguments

Usefulness of the showcased keyword-argument trick

  • Many see the reflection-based kwargs approach as “fun but not for real code.”
  • A common recommendation: define a separate parameter struct and pass it (optionally with default member initializers) instead of clever templates/macros; slightly more boilerplate, but far clearer and safer.
  • Several note that the need is usually not reordering arguments, but eliding some while keeping call sites readable.

Existing C/C++ techniques for named-style arguments

  • C-style patterns: argument-name comments at call sites, structs (named or anonymous), and pointers to structs, especially on embedded systems where stack usage and calling conventions matter.
  • C99 designated initializers and compound literals, and now C++20 designated initializers, already give a clear, built-in way to simulate keyword arguments via aggregates.
  • Some mention static analysis (clang-tidy’s argument-comment check) as a practical validator for commented arguments.

Reflection in C++26: promise vs complexity

  • Strong split in attitude: some are excited that compile-time reflection can replace code generators and help with serialization, UI generation, enums, and component systems; others see it as another layer of baroque syntax.
  • Compile-time reflection is praised as “zero-cost” and a better foundation than runtime reflection; others argue runtime reflection (dynamic invocation, plugin-like behavior) is more directly useful.
  • Concerns that C++ committee designs are constrained by extreme backward-compatibility, leading to opaque, over-generic interfaces and unpleasant syntax.

Design, safety, and language philosophy

  • Several posters deliberately restrict themselves to a small, simple subset of C++ (basic classes, STL, algorithms, lambdas; no raw loops/new/delete when possible) to avoid footguns and unreadable template metaprogramming.
  • Others argue complex template-heavy abstractions are sometimes justified in large codebases when they significantly reduce total code.
  • Skeptics see modern C++ evolution as chasing features other languages had decades ago, increasing complexity and technical debt; some suggest simply using languages with native kwargs and reflection (Python, JS, C#) instead.

Miscellaneous points

  • IDE parameter inlay hints are mentioned as a lightweight alternative for making positional calls readable.
  • There is side discussion on UB and lifetime around designated initializers, and on why GUIs or networking are not (or not yet) in the C++ standard library.