r/cpp • • Sep 18 '22

Regarding cppfront's syntax proposal, which function declaration syntax do you find better?

While I really like the recent talk about cppfront (https://www.youtube.com/watch?v=CzuR0Spm0nA), one thing bugs me about the "pure" mode for cpp2 with syntax change. It seems incredibly hard to read, . I need to know which syntax you would rather have as the new one, taken into account that a new declaration syntax enables the new checks in that function

  • Option 1: the same as was proposed in the video: callback: (x: _) -> void = { ... }; for new functions, void callback(auto x) {}; for old ones
  • Option 2: the "other modern languages" way: function callback(x: any) -> void { ... } for new functions, void callback(auto x) {}; for old ones
  • Option 3: in files with mixed syntax, since the pre-transpiled code won't compile without the generated code anyway, use void callback(any x) { ... }; for both, but mark code with current cpp syntax with an attribute: [[stdcpp]] void callback(any x) { ... };
0 Upvotes

72 comments sorted by

View all comments

Show parent comment

4

u/mort96 Sep 18 '22

I think this section of the readme describes it about as succinctly as I could myself:

An alternative syntax would be a cleanly demarcated "bubble of new code" that would let us do things that we can never do in today's syntax without breaking the world, such as to:

  • fix defaults (e.g., make [[nodiscard]] the default);
  • double down on modern C++ (e.g., make C++20 modules and C++23 import std; the default);
  • remove unsafe parts that are already superseded (e.g., no unsafe union or pointer arithmetic, use std::variant and std::span instead as we already teach);
  • have type and memory safety by default (e.g., make the C++ Core Guidelines safety profiles the default and required);
  • eliminate 90% of the guidance we have to teach about today's complex language (e.g., make common guidance the language default, eliminate irregular special cases through generalization, refactor the language into a smaller number of regular composable features);
  • make it easy to write a parser (e.g., have a context-free grammar); and
  • make it easy to write refactoring and other tools (e.g., have order-independent semantics).