Macros a la Rust? #6323
Replies: 2 comments 4 replies
-
The team has seemingly been reluctant to consider macro-like systems for C#. I would suggest that their complexity is probably the biggest stumbling block. These kinds of macros are effectively a separate language within the language which would require their own grammar and rules in the specification. With source generators none of that was necessary as the language itself did not change, and the compiler support required modest effort. |
Beta Was this translation helpful? Give feedback.
-
One significant advantage of Macro is giving developers a break while still keeping codes verbose. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I understand why C-style macros aren't supported by C#. They're nothing more than textual replacements with a whole mess of rules for when to substitute or not. However, has there been any discussion on Rust style macros?
There's source generators, sure, but they're not as elegant as Rust macros, and are more akin to Rust's "proc macros". For example, Rust's
vec![]
macro is defined roughly as:Sure, that could be faked with something like:
But that causes a copy, and if we wanted to do something more complex like define functions, C# can't do it (without source generators) whereas Rust's macros can.
Beta Was this translation helpful? Give feedback.
All reactions