# Metaprogramming: prefer functions with eval or macros?

**URL:** <https://discourse.julialang.org/t/metaprogramming-prefer-functions-with-eval-or-macros/127066>\
**Category:** General Usage\
**Created:** [March 17, 2025, 5:52pm UTC](https://discourse.julialang.org/t/metaprogramming-prefer-functions-with-eval-or-macros/127066 "2025-03-17T17:52:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 17, 2025, 6:27pm UTC](https://discourse.julialang.org/t/metaprogramming-prefer-functions-with-eval-or-macros/127066/2 "2025-03-17T18:27:01Z")

</div>

> [@mattsignorelli](#):
>
> My instinct tells me the code generation via a macro is certainly done statically, and therefore would be preferred, but perhaps the function + eval is also fully static and so either is ok.

Function + `eval` is definitely _not_ static, it’s done at runtime. That also means it’s typically used for fundamentally different purposes, e.g. evaluating user input interactively, when the desired information is only available at runtime.

Of course, first you should ask yourself whether you should be doing metaprogramming in the first place. It’s a great tool to have a available on occasion, but 99% of the time you should be using ordinary functions and data structures. See also the discussion in: [How to warn new users away from metaprogramming](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022)

---

_[View the full topic](https://discourse.julialang.org/t/metaprogramming-prefer-functions-with-eval-or-macros/127066)._
