Seeking comments on my draft blog post about my favorite features of Rust

I plan to publish a blog post titled Other Reasons Why Rust Is My Favorite Programming Language. It's currently a draft.

I'd greatly appreciate any feedback you could provide. I've only been coding in Rust for about a year so I may have gotten some things wrong. Please comment directly on the document.

There's one area in particular where I need help. After explaining the Rust preprocessor, I attempt to assuage the fears of those who maintained code bases in the 1990s by explaining that unlike the C/C++ preprocessor, you can't do crazy things like redefine language keywords or invent your own macro language. However, I don't provide the technical details to back that up because I don't understand Rust's preprocessor well enough. Your guidance would be greatly appreciated on this point.

Thanks in advance (and more thanks later!)

2 Likes

The Rust macro system is usually not called a "preprocessor".

Is it? I'm not sure. By Wikipedia:

In computer science, a preprocessor is a program that processes its input data to produce output that is used as input to another program. The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.

The Rust compiler performs macro expansion before most of the compilation stages, but not all of them. It is definitely not "a program that processes its input to produce output that is used as input to another program". However, one can imagine a C compiler that does the same, although the nature of C prevents even lexical analysis to be done before preprocessing. So, it is a preprocessor?

At least the official books claim it is not:

In Rust there is no preprocessor

Tips for embedded C developers - The Embedded Rust Book (rust-embedded.org)

It is indeed not called a preprocessor.

1 Like

I think I said it pretty explicitly. I just wondered if that's right.

It's not a preprocessor because if you implement it that way you'll quickly see that it cannot maintain hygiene the way it's supposed to.

This is why, for example, you can't necessarily compile the result of cargo expand and get the same results.

1 Like

The blog post will be significantly improved thanks to your comments; thank you everyone who commented. It'll take me a couple weeks to accommodate all the comments. I may also implement the py2format!() example macro to better understand macros.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.