I tend to use meta-programming quite a bit when I write code. The benefit of a 
macro over a simple procedure is that you can re-write code during compile 
time. This can be used to create a nicer interface for yourself, reducing 
errors and increasing readability. I wrote an article about that here: 
<https://peterme.net/metaprogramming-and-read-and-maintainability-in-nim.html>

It can also be used to turn high-abstraction code into something more 
low-level. 
[Zero-functional](https://github.com/zero-functional/zero-functional) is a nice 
example of a macro that turns one style of programming which would normally be 
expensive to do in Nim into something that's much cheaper. I also use this 
quite a bit in my custom keyboard firmware (along with the great type-system) 
both for increasing performance, but also the aforementioned read and 
maintainability. You can see my [NimConf 
talk](https://www.youtube.com/watch?v=dcHEhO4J29U) on the subject or my [video 
series](https://www.youtube.com/watch?v=XoOp3UfKXQY) where I show the entire 
implementation and explain what I'm doing and why as I go along.

Reply via email to