<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="111945" data-post-id="111945">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="axelson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/axelson/120/26351_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  axelson
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Scenic Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I just want to quickly note that one of the goals of Absinthe 1.5 is to need less macros to dynamically define a schema, and I know other people are working on making it simpler as well.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111945" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-programmatically-call-macros/19408/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-111945" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111945"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="111947" data-post-id="111947">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Eiji" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Eiji/120/36743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Eiji
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The problem is that people don’t want to write <code>absinthe</code> schema with <code>absinthe</code> macro, but dynamically <strong>generate</strong> <code>absinthe</code> schema based on <code>ecto</code> database representation + some extra checks and rules.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111947" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-programmatically-call-macros/19408/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-111947" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111947"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="111948" data-post-id="111948">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cjbottaro" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cjbottaro/120/1469_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cjbottaro
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh… well now we’re going to get into a difference of opinions.</p>
<blockquote>
<p>so you can do:</p>
</blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Document.InputObjects.Schema do
  # …

  defp filter_name({:__aliases__, [alias: false], list}) do
    list
    |&gt; List.delete("Schema")
    |&gt; Enum.join()
    |&gt; Macro.underscore()
    |&gt; append("_filter")
    |&gt; String.to_atom()
  end

  defp append(string, suffix), do: string &lt;&gt; suffix

  # …
end
</code></pre>
<p>Just because we <em>can</em> do something doesn’t mean we should… or in this case, it’s simpler and/or more readable to eval the args before passing them, instead of passing AST tuples. Also, the arguments are not coming from “user input” so there is no concern with eval’ing them.</p>
<p>I feel like there are two approaches to Elixir metaprogramming:</p>
<ul>
<li>We’re going to help you and hold your hand (and here are the module/funcs to do so)</li>
<li>Eff it, here’s the AST and do as you please before sending to the interpreter to execute</li>
</ul>
<p>So I see what you’re saying: everything can be done at an extremely low level. But if I can do stuff at a higher level, that’s supported by the language’s standard lib. Shouldn’t I do that before just mucking with ASTs?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111948" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-programmatically-call-macros/19408/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-111948" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111948"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="111950" data-post-id="111950">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Eiji" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Eiji/120/36743_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Eiji
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cjbottaro" data-post="14" data-topic="19408">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cjbottaro/48/1469_2.png" class="avatar"> cjbottaro:</div>
<blockquote>
<p>So I see what you’re saying: everything can be done at an extremely low level. But if I can do stuff at a higher level, that’s supported by the language’s standard lib. Shouldn’t I do that before just mucking with ASTs?</p>
</blockquote>
</aside>
<p>Firstly <code>AST</code> is not extremely low level if we are talking about <code>Elixir</code>. <img src="https://forum.elixirforum.com/uploads/default/original/2X/2/20c9c52366de24191270f0b11311379ce60ac82d.gif?v=15" title=":077:" class="emoji emoji-custom" alt=":077:" loading="lazy" width="20" height="20"></p><aside class="quote quote-modified" data-post="8" data-topic="6104">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/48/2677_2.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/can-someone-enlighten-me-on-this-piece-of-code/6104/8" rel="nofollow">Can someone enlighten me on this piece of code?</a> <a class="badge-category__wrapper " href="/c/questions-help/questions/53" rel="nofollow"><span data-category-id="53" style="--category-badge-color: #C14BFB; --category-badge-text-color: #000000; --parent-category-badge-color: #C14BFB;" data-parent-category-id="171" data-drop-close="true" class="badge-category --style-square --has-parent" title="Elixir Questions / Help"><span class="badge-category__name">Questions</span></span></a>
    </div>
  </div>
  <blockquote>
    Eh, not really like assembler, it is the very definition of AST.  Elixir’s AST.  <img width="20" height="20" src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title="slight_smile" alt="slight_smile" class="emoji"> 
The compilation process goes:  Elixir → Elixir’s AST (what quote gives you) → Erlang (Abstract Format, basically it’s AST) → Core Erlang → BEAM 
With a variety of translators along the way too.  <img width="20" height="20" src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title="slight_smile" alt="slight_smile" class="emoji"> 
Basically take this Elixir: 
defmodule :tester do

  def hi, do: "there"

end

To this Elixir AST: 
{:defmodule, [context: Elixir, import: Kernel],
 [:tester,
  [do: {:def, [context: Elixir, …
  </blockquote>
</aside>

<p>Well … I have one really good example from my experience …</p>
<p>My first job … I have worked with Ruby/Rails. I saw really small monkey patching usage from someone who was more experienced than me. I liked how it’s simple (so there was no need to change existing code) and I have stupidly changed file with just few lines of monkey patching into weird file with hundreds of lines with monkey patching.</p>
<p>If something is supported it does not mean that it should be always used. Especially when we are talking about evals. Look … I believe that <code>Joomla!</code> and <code>Wordpress</code> developers are not stupid. Same goes to developers of (at least most popular) extensions for those projects. The problem is that lots of sites was trivially hacked by adding <code>PHP</code> code into image files - <strong>just because</strong> they used <strong>eval</strong>.</p>
<p>Sure, one module looks safe, but can you guarantee that this will be still safe after few rotations in <code>dev</code> team? Can you guarantee that it will be still safe after somebody in team decides to move such generator (with <code>eval</code> call) to open source library? Software is changing really rapidly.</p>
<p>If we are going always with easiest solution then we will end with something like <code>Windows</code> in few weeks/months. <code>Windows</code> was created by definitely good developers, but looking how it changes in years we see that something is definitely wrong. For example compare modern (with rewritten code) <code>Plasma 5</code> features and requirements with what offers <code>Windows</code>’s builtin window manager. I can’t do even as good job as that made in both projects, but still I (being not experienced in OS programming) see huge differences.</p>
<p>Also my solution is not about only “low level”. We have here typical pattern matching which prevents to add data of <strong>any</strong> type. We can always add simple guard to check if module have <code>Schema</code> part in list too without bigger problem.</p>
<p>Summary:</p>
<ol>
<li>It’s safe - no matter who will use it and no matter if you made mistake</li>
<li>It’s at least as simple as with <strong>eval</strong> (in implementation)</li>
<li>It’s definitely faster solution</li>
</ol>
<p>Therefore I’m not sure what’s wrong with my hint.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="111950" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-to-programmatically-call-macros/19408/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-111950" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="111950"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>