# How to warn new users away from metaprogramming

**URL:** <https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022>\
**Category:** Internals & Design\
**Tags:** question, proposal\
**Created:** [February 22, 2020, 5:33pm UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022 "2020-02-22T17:33:51Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 24, 2020, 8:48pm UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/21 "2020-02-24T20:48:19Z")

</div>

I feel fortunate to have recognized early on that metaprogramming was generally above my skill set! Based on the number of questions that get posed to the forum about it, I think it has saved me some headaches.

But I definitely appreciate the efforts of those who have ventured into the pits…

---

<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:** [February 24, 2020, 11:22pm UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/22 "2020-02-24T23:22:18Z")

</div>

> [@mbauman](#):
>
> I don’t see a strong need to warn folks away from metaprogramming in general. Using a `for` loop to define lots of functions or methods […] isn’t going to lead to major issues

The biggest problems I see with mis-use of metaprogramming are

- people who fundamentally don’t understand what macros are and when they run, and are trying to use them for runtime calculations or think they can do something other than saving typing. Consequence: frustration and confusion.

- people who want to pass function arguments as strings or expressions rather than as…functions. Consequence: frustration and confusion about scope, and terrible performance if they get it to work.

- trying to use lots of generated variables rather than using a container data structure (e.g. a `Dict`). Consequence: frustration and confusion about scope, and (probably) inflexible and unreadable code.

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [February 25, 2020, 8:18am UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/23 "2020-02-25T08:18:35Z")

</div>

> [@ChrisRackauckas](#):
>
> Even when making a DSL, I think the “non-DSL” version should be very clear. For example, I wish JuMP had documented their macro-free interface, so the macro was “just nicer syntax”.

Not to derail the conversation, but: One could argue that MathOptInterface is the macro-free interface, and JuMP is “just nicer syntax”.

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [February 25, 2020, 10:13am UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/24 "2020-02-25T10:13:16Z")

</div>

On the other side macro are fun and an exciting feature when you come from other languages that don’t have them. That’s something that motivated me to go into Julia early on, and even though I made all the common mistakes with macro it was still fun (and useful) to learn. That’s also maybe why we see all these beginners misusing macros.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [February 25, 2020, 10:19am UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/25 "2020-02-25T10:19:20Z")

</div>

> [@jonathanBieler](#):
>
> macro are fun and an exciting feature

Just to clarify, the proposal is about the scenario where macros yield difficult, buggy, inelegant, and slow solutions. It is my impression from discussions on this forum that the new users who get into these are not having fun — quite the opposite.

There is no intention to deny the usefulness of macros, or to de-emphasize their importance in Julia and how they give a comparative advantage to the language.

Also, from this discussion I think that the title of the topic is too broad: other aspects of metaprogramming are not as affected as macros.

---

<div class="post-metadata">

**Author:** ![YongHee-Kim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yonghee-kim/32/5965_2.png) [@YongHee-Kim](https://discourse.julialang.org/u/YongHee-Kim)\
**Post date:** [February 28, 2020, 1:03am UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/26 "2020-02-28T01:03:49Z")

</div>

> [@Tamas\_Papp](#):
>
> - a warning at the beginning of the metaprogramming chapter in the manual

It would be a good start. And if documentation can be divided into “Basic”, “Advanced” section and put metaprogramming under the “Advanced” section would help shun away new users from trying it.

Current TOC may make one think that metaprogramming is as easy and essential as Multi-dimensional Arrays and Missing Values

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/9/394db3b4b2f9c4a91d43e6f2e7c25060d4c58f84.png)

---

<div class="post-metadata">

**Author:** ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)\
**Post date:** [February 28, 2020, 1:16am UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/27 "2020-02-28T01:16:34Z")

</div>

Absolutely. MathOptInterface is the macro-free interface under JuMP.

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [November 6, 2022, 2:17pm UTC](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022/28 "2022-11-06T14:17:56Z")

</div>

Do folks think [this pr](https://github.com/JuliaLang/julia/pull/47469) adequately gathers the sense of this thread?

[Previous page](https://discourse.julialang.org/t/how-to-warn-new-users-away-from-metaprogramming/35022.md?page=1)
