I say this because someone coming from a functional language might be betrayed by their instincts here: it is relatively rare for Rust users to write macros themselves, and macro-heavy Rust code would generally be regarded as peculiar/unidiomatic.
Unfortunately the language documentation isn't helpful either, looking at the docs for println! [0] doesn't explain the arguments that it takes (other than referring to format!, which is another macro [1]...) or what the return value of the macro is.
[0] https://doc.rust-lang.org/std/macro.println.html [1] https://doc.rust-lang.org/std/macro.format.html
You don't "have to" understand the `println!` implementation in order to use it. It certainly helps like it does for any other API, but it can be treated as a blackbox, and still be able to use it.
I see many tech:nerd people explain this bottom-up instead of bottom-down because they can’t imagine skipping details for later. The reality is that students are intrigued by “I’ll explain what that means later” and it builds interest.
I explain how our website works by first telling a big lie: your computer requests a webpage and we have one big computer that replied with the answer. I then explain that I just lied. I then break it down: a web page requires many elements. Each requested individually. I then explain we don’t have one big computer but a cluster behind a load balancer. I then explain the many benefits of a load balancer. Then I explain that the web cluster depends on databases and other services.
All-in-all I expose 5-6 “lies” as I break down each component.
I’ve gotten positive feedback from both non-developers, entry-level developers, and expert developers.
I’ve also seen people give a bottom up description and everyone was confused at the end.
Why do top-down descriptions work better even though they initially gloss over (lie) To the audience?
Because the high level description gives The audience a mental roadmap to follow. Then we back up and walk through that roadmap in more detail. Then we walk through again in even more detail.
The entire time the audience understands where we are going and fits each bit of new information into their mental model, expanding it as we go.
Here’s how it feels to be explained to in a bottom-up manner: imagine I spent an hour with you listing out left and right turns. At the end of the hour I tell you “and that’s how You drive from NYC fo San Francisco”. JFC, Tom, couldn’t you have started with that!?!?
Don’t be that guy.
An explanation isn’t a murder-mystery novel with a surprise ending. Start with “these butler did it” and work backwards from there.
At Bell Labs we had a saying about presentations: “first show us your conclusion slide. If we disagree, rewind to the first slide and show us your talk. You have our interest. If we agree, stop. We can all go to lunch early.”
Some topics, this can’t be helped with as much, but in most cases, starting high level and progressively peeling back layers is a lot more effective.
That’s how most education is presented as well. It’s usually only domain experts who DON’T teach that think every little detail is valuable up front.
But on the other hand it means that people are less inclined to abuse them and they're a lot more hygienic than C-style macros...
I’ve written some fairly heavy Rust macro code, and I almost never need recursion— the repetition primitives generally prove sufficient for my needs. What are you doing that needs all the recursion?
https://github.com/rust-lang/rust/search?q=macro_rules&type=
Looking at some of those and reading https://doc.rust-lang.org/rust-by-example/macros/syntax.html and https://doc.rust-lang.org/reference/macros-by-example.html can potentially be instructive.
Jon Gjengset series Crust of Rust is amazing.
You can use both. You can run them more than once, perhaps changing the source with a sed or perl script between passes.