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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Some thoughts:</p>
<aside class="quote no-group" data-username="OndrejValenta" data-post="1" data-topic="48314">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ondrejvalenta/48/16421_2.png" class="avatar"> OndrejValenta:</div>
<blockquote>
<ul>
<li>What do you return from methods? Are there methods that are returning just plain values in your projects and when do you switch to {:ok, data…} tuples?</li>
</ul>
</blockquote>
</aside>
<p>I will typically not return <code>{:ok, &lt;data&gt;}</code> unless the function may also return <code>{:error, &lt;data&gt;}</code>.  The extra ceremony of the result tuple doesn’t really provide any value if the only options are the value or raising/crashing/other non-result.</p>
<aside class="quote no-group" data-username="OndrejValenta" data-post="1" data-topic="48314">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ondrejvalenta/48/16421_2.png" class="avatar"> OndrejValenta:</div>
<blockquote>
<ul>
<li>Do you return {:ok} or just plain :ok? For me {:ok} is more consistent with {:ok, data}, for others it’s not.</li>
</ul>
</blockquote>
</aside>
<p>Just <code>:ok</code>.  At first I did return <code>{:ok}</code>… not so much because I gave it any thought but it was my default because I was just starting out with Elixir, and as you point out, it felt consistent.  I later reverted all that to just be <code>:ok</code>.  As I got better versed with prior practice in Elixir, the common libraries used like Ecto, and having made use of a number of Erlang OTP modules, there seemed to be a preference to not wrap a plain <code>:ok</code> atom return value in an extra data structure.  So while <code>{:ok}</code> felt more immediately consistent with <code>{:ok, &lt;data&gt;}</code> I chose to have greater consistency with common practice.  I expect that anyone newly coming to my code would be on slightly firmer ground if my code met familiar existing practice.</p>
<p>And maybe that’s the guidance I would really offer.  Any set of documented guidelines will probably be better if some deference is given to historic practices… using perhaps the Elixir/Erlang Standard Libraries &amp; OTP as a reference point…  or at least explain why those historic practices are not being adopted when they might otherwise apply.  They might not be the best, or even clearly consistent (for example, I see Erlang’s ETS module returning <code>&lt;data&gt;</code>, <code>{ok, &lt;data&gt;} | {error, reason}</code>, <code>ok</code>, but also <code>true</code>) but in general they are expected.</p>
<p>Other notes related to your questions (from my point of view).</p>
<p>Function parameters I will typically make explicit/individual required parameters.  Some deference in ordering is made to how a function might be part of a data transformation pipelines such that |&gt; usage is more natural.  Optional parameters are Keyword lists &amp; maps.  The exception to this in my code is when the “record” (generically speaking) is the parameter.  Changeset functions with Ecto are a good example of this, both the starting data struct and the changes are single parameters (usually) because the record itself is the value, albeit a complex one.</p>
<p>Return data will in part depend on if I expect the function to participate in data transformation pipelines or not.  If so, the return value is built to facilitate that usage across the functions that it might be expected to work with.  Otherwise it really depend on the consumer of the result.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="252897" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-252897" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="252897"
                     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="252998" data-post-id="252998">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Can we just return an exception without raising it?<br>
Also, how can we typespec a custom exception? I see very little info about exceptions in the docs</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="252998" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-252998" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="252998"
                     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="253001" data-post-id="253001">
  <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">
								<p>Yes. Exceptions are just specialized structs. Instead of <code>raise ArgumentError, "Something"</code> you can do <code>ArgumentError.exception("Something")</code> and you get that struct. You can then later do <code>raise exception</code> if needed.</p>
<p>As for typespecs I’d use <code>Exception.t</code>.</p>
<p>See <a href="https://hexdocs.pm/elixir/Kernel.html#defexception/1" class="inline-onebox" rel="nofollow">Kernel — Elixir v1.20.2</a> on how to create custom exceptions as well as <a href="https://hexdocs.pm/elixir/Exception.html" class="inline-onebox" rel="nofollow">Exception — Elixir v1.20.2</a> on the behaviour to implement (and possibly overwrite the default implementations for).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253001" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-253001" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253001"
                     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="253004" data-post-id="253004">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hmm not sure how we can get any additional parameters with this approach</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253004" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-253004" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253004"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="253005" data-post-id="253005">
  <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">
								<p>Exceptions are structs. You can put any data you need on them – and due to the behaviour of exceptions still make sure those can be transformed to a string based message.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253005" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-253005" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253005"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="253007" data-post-id="253007">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>hmm so if we used <code>Exception.t()</code> how we describe additional data which this custom exception handles?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253007" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-253007" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253007"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="253008" data-post-id="253008">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I might be doing something wrong, but I’m using custom exceptions and a simplified version looks something like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MsbmsSystError do  
  @type t :: %__MODULE__{
          code: Types.msbms_error(),
          message: String.t(),
          cause: any()
        }

  @enforce_keys [:code, :message, :cause]
  defexception code: :undefined_error,
               message: "undefined error",
               cause: nil
end
</code></pre>
<p>When I reference that in other typespecs I just do something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@spec some_function() :: :ok | {:error, MsbmsSystError.t()}
</code></pre>
<p>I can also raise, etc. using that definition.  I haven’t met any friction with that so far and everything that deals with handling exceptions works as expected so far.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253008" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-253008" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253008"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="253010" data-post-id="253010">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for sharing your experience</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253010" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-253010" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253010"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="253011" data-post-id="253011">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I also strongly believe the point <a class="mention" href="/u/ondrejvalenta" rel="nofollow">@OndrejValenta</a> raised.<br>
Proper error handling in MVP to enterprise-level apps is very crucial. So an official guide about how to organize code around errors will be really valuable. At least mentioning some patterns in the guide would do the job.</p>
<p>As we saw there are a lot of third-party articles about it and some even can cause lot of trouble in the long run if you didn’t seriously take a look</p>
<p>Elixir has freedom, but too much freedom can shoot our own foot <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> so a good official guide about this would be super useful</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253011" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-253011" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253011"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="253017" data-post-id="253017">
  <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>Have you read the <a href="https://elixir-lang.org/getting-started" rel="nofollow">official guides</a>?  You get a feel for how to handle expected errors via return tuples/status codes.  And then there is the section on <a href="https://elixir-lang.org/getting-started/try-catch-and-rescue.html" rel="nofollow">try/catch/rescue</a> which specifically talks about exceptions and even touches on “let it crash”.  Perhaps there could be a named section on dealing with expected errors, but I wouldn’t say this information isn’t available in official guides.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="253017" 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/what-are-your-recommendations-on-method-signatures-and-return-values/48314/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-253017" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="253017"
                     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 #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/48314/load_more?page=3">Load more posts (21 remaining)</a>
</div></template></turbo-stream>