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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m relatively new to Elixir but encountered some similar frustration with multi-line formatting at the beginning, though I’ve since gotten more used to it. I realized, however, that I was often overmatching in order to reduce line count at the expense of readability.</p>
<p>The standard I’ve started to stick to is to only match in the function head on the minimum amount necessary to make that function body applicable to the given arguments. Everything else can be destructured in the function body. This means more lines of code on average, but function heads become more readable and convey more information by highlighting the specific elements of arguments that they’re <em>really</em> matching on.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256590" data-batch-url="/posts/batch_likers">
                        4
                      </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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-256590" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256590"
                     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 #21"></div>
  </section>
</div>
    <div class="postbit" id="256595" data-post-id="256595">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That first formatted function head actually made me slightly queasy <img src="https://forum.elixirforum.com/images/emoji/apple/rofl.png?v=15" title=":rofl:" class="emoji" alt=":rofl:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256595" 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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-256595" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256595"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="256604" data-post-id="256604">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>While we’re somewhat on the topic… has there ever been any public discussion of Elixir adopting JavaScript-style destructuring for atom keys in maps? <code>%{foo}</code> equivalent to <code>%{foo: foo}</code>. At a glance I can’t see a conflict with existing syntax.</p>
<p>I suppose there may be a conflict with the construction syntax <code>%{foo | bar: “bar”}</code> which could be problematic, but I don’t think the above is allowed without the pipe.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256604" 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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-256604" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256604"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="256605" data-post-id="256605">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="zachallaun" data-post="24" data-topic="49136">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachallaun/48/29208_2.png" class="avatar"> zachallaun:</div>
<blockquote>
<p>While we’re somewhat on the topic… has there ever been any public discussion of Elixir adopting JavaScript-style destructuring for atom keys in maps? <code>%{foo}</code> equivalent to <code>%{foo: foo}</code>. At a glance I can’t see a conflict with existing syntax.</p>
</blockquote>
</aside>
<p>Many. Before and after this blog post: <a href="https://andrealeopardi.com/posts/a-story-of-regret-and-retiring-a-library-from-hex/" class="inline-onebox" rel="nofollow">A story of regret and retiring a library from Hex – Andrea Leopardi</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256605" data-batch-url="/posts/batch_likers">
                        2
                      </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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-256605" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256605"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="256607" data-post-id="256607">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for the context and history!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256607" 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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-256607" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256607"
                     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 #25"></div>
  </section>
</div>
    <div class="postbit" id="256608" data-post-id="256608">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="zachallaun" data-post="22" data-topic="49136">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/zachallaun/48/29208_2.png" class="avatar"> zachallaun:</div>
<blockquote>
<p>The standard I’ve started to stick to is to only match in the function head on the minimum amount necessary to make that function body applicable to the given arguments. Everything else can be destructured in the function body.</p>
</blockquote>
</aside>
<p>Here, I’m just curious about something. I wonder wether there is a performance gain between getting “sub-parameters” in a function head instead of doing it inside its body.</p>
<p>And more specifically:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">a = param.a
b = param.b
</code></pre>
<p>vs</p>
<blockquote>
<p>%{a: a, b: b} = param</p>
</blockquote>
<p>Well this is not really about the head or the body of the function…</p>
<aside class="quote no-group" data-username="thiagomajesk" data-post="11" data-topic="49136">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/thiagomajesk/48/31904_2.png" class="avatar"> thiagomajesk:</div>
<blockquote>
<p>The formatter is something that I have a bittersweet feeling about and it’s perhaps the tool that I least like in the ecosystem. It’s great to keep a codebase consistent across teams if you don’t really want to think about it.</p>
</blockquote>
</aside>
<p>Exactly when we are working with other people, I think we have to follow the same rules in formating the code.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256608" 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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-256608" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256608"
                     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 #26"></div>
  </section>
</div>
    <div class="postbit" id="256611" data-post-id="256611">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Kurisu" data-post="27" data-topic="49136">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kurisu/48/14820_2.png" class="avatar"> Kurisu:</div>
<blockquote>
<p>Here, I’m just curious about something. I wonder wether there is a performance gain between getting “sub-parameters” in a function head instead of doing it inside its body.</p>
</blockquote>
</aside>
<p>You could benchmark it, but I <em>strongly</em> suspect no measurable difference in 99.9% of cases that Elixir users care about. You’d theoretically be doing fewer lookups and nil/membership comparisons with access in the body, but I wouldn’t be surprised if the Erlang compiler ends up “pre-loading” the data you’re going to be using in function bodies anyways. (I’m not an expert here at all, I just know enough to know that I know nothing about compiler optimization tricks that can be pulled to make stuff fast.)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256611" data-batch-url="/posts/batch_likers">
                        1
                      </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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-256611" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256611"
                     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 #27"></div>
  </section>
</div>
    <div class="postbit" id="256673" data-post-id="256673">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Not using a single pipe is something that was beat into me.  While hurts readability in some cases, I never really found a big problem with it, yet here we are.  I do find in some cases it makes sense, like I have some factory helpers like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">build(:article)
|&gt; mark_published()
</code></pre>
<p>which aren’t so nice to read like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">mark_published(build(:article))
</code></pre>
<p>so I end up writing:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">:article
|&gt; build()
|&gt; mark_published()
</code></pre>
<p>which isn’t the worst but there is something odd-looking about it and it appeases credo and my inherited distaste for single pipes.</p>
<p>It also works with the pro-trailing comma argument for diffs:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def changeset(entity, attrs) do
  cast(entity, attrs, [:one, :two, :three])
end
</code></pre>
<p>Now if I want to pipe on a validation at a later date, the diff is a bit more confusing than if I had just originally had:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def changeset(entity, attrs) do
  entity
  |&gt; cast(attrs, [:one, :two, :three])
end
</code></pre>
<p>Anyway, I’m getting on a bit of tangent here.  Regardless of all that, I’m very pro-community standards and follow those I don’t necessarily like.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="256673" data-batch-url="/posts/batch_likers">
                        3
                      </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/obsession-with-line-length-and-hideous-formatting-am-i-writing-elixir-wrong/49136/29">Post #28</a>
	                </div>
	            </div>
              <div id="likers-container-256673" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="256673"
                     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>