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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think the time/effort required to fix the bad code to use <code>MyStruct.new</code> etc is exaggerated. It’s got to be less than 30mins. Surely we should spend the time to fix our bugs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377369" 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/runtime-calculated-default-values-for-structs/73189/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-377369" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377369"
                     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="377370" data-post-id="377370">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mudasobwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/120/5298_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mudasobwa
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Cure</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah, <code>Lazy</code> should have been deprecated and removed, I simply did not have time to bother.</p>
<aside class="quote no-group" data-username="ffloyd" data-post="8" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/48/10538_2.png" class="avatar"> ffloyd:</div>
<blockquote>
<p>I haven’t found dedicated section about “calculated”</p>
</blockquote>
</aside>
<p>That’s because the library is not about calculated values (btw, they are truly calculated, not dynamic defaults; when any of values it depends on has changed, the value in calculated field(s) is also re-calc’ed.)</p>
<p>This library is about handy generation od property-data for property-based testing in the first place, it just supports calculated values by accident.</p>
<aside class="quote no-group" data-username="ffloyd" data-post="8" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/48/10538_2.png" class="avatar"> ffloyd:</div>
<blockquote>
<p>I cannot do this on a big production project and dependencies.</p>
</blockquote>
</aside>
<p>I am not sure how would you expect dependencies to automagically convert to support dynamic defaults, let alone it might break them. For a big production project, I would typically comment out the declaration of the struct, collect all compilation errors, and fix them one by one. Changing them to a constructor would probably suffice your needs, but I might be mistaken.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377370" 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/runtime-calculated-default-values-for-structs/73189/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-377370" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377370"
                     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="377377" data-post-id="377377">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ffloyd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/120/10538_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ffloyd
                    <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">
								<aside class="quote no-group" data-username="cmo" data-post="12" data-topic="73189" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/48/19618_2.png" class="avatar"> cmo:</div>
<blockquote>
<p>I think the time/effort required to fix the bad code to use <code>MyStruct.new</code> etc is exaggerated. It’s got to be less than 30mins. Surely we should spend the time to fix our bugs.</p>
</blockquote>
</aside>
<p>Isn’t 29 mins for adding a dynamic default… too much? It’s less than minute in many other languages and a pretty common feature.</p>
<p>And making defaults dynamic in Ecto is definitely more than 30 mins.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377377" 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/runtime-calculated-default-values-for-structs/73189/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-377377" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377377"
                     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="377378" data-post-id="377378">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ffloyd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/120/10538_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ffloyd
                    <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">
								<aside class="quote no-group" data-username="mudasobwa" data-post="13" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/48/5298_2.png" class="avatar"> mudasobwa:</div>
<blockquote>
<p>how would you expect dependencies to automagically convert to support dynamic defaults, let alone it might break them.</p>
</blockquote>
</aside>
<p>For example <code>Estructura</code>. With my current proposal I would just use it with <code>defdynstruct</code>. It still generates <code>__schema__</code> functions, etc. I expect all the features of <code>Estructura</code> to just work. Am I right or it somehow relies on <code>%A{} == %A{}</code>? (that’s the only promise that is broken by <code>defdynstruct</code>).</p>
<aside class="quote no-group" data-username="mudasobwa" data-post="13" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/48/5298_2.png" class="avatar"> mudasobwa:</div>
<blockquote>
<p>I would typically comment out the declaration of the struct, collect all compilation errors, and fix them one by one.</p>
</blockquote>
</aside>
<p>Is it adequate price for introducing dynamic default?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377378" 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/runtime-calculated-default-values-for-structs/73189/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-377378" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377378"
                     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="377392" data-post-id="377392">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Even though I do understand the ask, I’m not sure it’s a good idea. Especially the <code>%A{} == %A{}</code> argument is a very strong one. Thus we shouldn’t touch the raw struct.</p>
<p>Also, I don’t really see the big value of <code>struct/2</code> over a <code>A.new/1</code></p>
<p>Not to mention that a <code>defdynstruct</code> sounds very clunky.</p>
<p>You could have an annotation like <code>@init :myinit</code> (if you like with some syntactic sugar with name convention so you only need to define only an <code>__init__</code> function), BUT I would even vote against that, because of the classical rule:</p>
<blockquote>
<p>don’t surprise</p>
</blockquote>
<p>The developer would need to know that you do dynamic initialisation. IMHO it’s better to be explicit.</p>
<p>As a library creator you should think carefully on whether you want to have statically or dynamically created structs. Provide a <code>new/1</code> if you might want to extend it to a dynamic struct in the future (apply SOLID principles). In that case you might not want to expose the actual data structure.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377392" 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/runtime-calculated-default-values-for-structs/73189/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-377392" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377392"
                     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="377396" data-post-id="377396">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="ffloyd" data-post="14" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/48/10538_2.png" class="avatar"> ffloyd:</div>
<blockquote>
<p>Isn’t 29 mins for adding a dynamic default… too much?</p>
</blockquote>
</aside>
<p>Don’t know but don’t think so. This thread already  took more time; so does reviewing the changes, testing etc.</p>
<p>Using a factory seems to be a pretty nice option; making the data structure an implementation detail.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377396" 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/runtime-calculated-default-values-for-structs/73189/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-377396" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377396"
                     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="377400" data-post-id="377400">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I appreciate the initiative, I really do. For a language to survive and thrive it needs people to think about it, tinker with it, criticize it, etc. So thanks for that.</p>
<p>However, I’m not a fan of this proposal for two reasons:</p>
<ol>
<li>I like the fact that elixir does not have as many concepts to learn as other languages. We should be very careful with adding more complexity.</li>
<li>The fact that <code>%A{} == %A{}</code> wouldn’t work anymore is killer.</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377400" 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/runtime-calculated-default-values-for-structs/73189/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-377400" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377400"
                     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="377404" data-post-id="377404">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ffloyd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/120/10538_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ffloyd
                    <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">
								<aside class="quote no-group" data-username="FlyingNoodle" data-post="18" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/flyingnoodle/48/32593_2.png" class="avatar"> FlyingNoodle:</div>
<blockquote>
<p>So thanks for that.</p>
</blockquote>
</aside>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/heart.png?v=15" title=":heart:" class="emoji only-emoji" alt=":heart:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="FlyingNoodle" data-post="18" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/flyingnoodle/48/32593_2.png" class="avatar"> FlyingNoodle:</div>
<blockquote>
<p><code>%A{} == %A{}</code> wouldn’t work anymore is killer.</p>
</blockquote>
</aside>
<p>I see. <code>%A{} != %A{}</code> is kind of ugly thing, I agree. I like the principle “a cure should not be worse than a disease”. I proposed a cure, but it has this side effect. Therefore, if we agree that disease is worse than having <code>%A{} != %A{}</code>, the proposal has a chance. So, let me show symptoms of “disease” more explicit.</p>
<p>My initial problem was about “Ecto cannot do dynamic defaults”. There is no proper workaround. <code>autogenerate</code> has pretty different behavior and does not work for virtual fields. I was thinking about proposing something like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Reminder do
  use Ecto.Schema

  schema "users" do
    field :remind_at, :datetime, default_fn: &amp;today_plus_10_days/0
    # ... rest of the fields ...
  end
end
</code></pre>
<p>Then I thought about implementation. Usually we create a record like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">%Reminder{}
|&gt; create_changeset()
</code></pre>
<p>Ecto also <a href="https://hexdocs.pm/ecto/3.13.4/Ecto.Repo.html#c:insert!/2" rel="noopener nofollow ugc">explicitly allows</a> to do:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Repo.insert(%Reminder{})
</code></pre>
<p>Where this “default_fn” should be invoked? There is no guarantee that changeset will be used so we cannot put it into changeset. Patch <em>all</em> changeset functions and Repo functions to invoke “default_fns”? Even if we do this we have another problem: <a href="https://hexdocs.pm/ex_machina/readme.html#overview" rel="noopener nofollow ugc">people do factories</a> in the following way:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def reminder_factory(...) do
  %Reminder{
     user: build(:user)
   }
end
</code></pre>
<p>How to make “default_fn” to work here?</p>
<aside class="quote no-group" data-username="a-maze-d" data-post="16" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/a-maze-d/48/31720_2.png" class="avatar"> a-maze-d:</div>
<blockquote>
<p>As a library creator you should think carefully on whether you want to have statically or dynamically created structs.</p>
</blockquote>
</aside>
<p>If even creators of Ecto (and ExMachina) fell into the trap that locked them from providing reliable dynamic defaults without huge refactoring - it means we have a problem in the language design.</p>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/person_fencing.png?v=15" title=":person_fencing:" class="emoji" alt=":person_fencing:" loading="lazy" width="20" height="20"> <em>This is the disease I’m fighting with here.</em> All the code in this message is idiomatic and comes from widely used libraries. It’s not about mere “struct creation with defaults”, it’s about <em>preventing libraries from supporting dynamic defaults</em>.</p>
<p>While I do not like introducing <code>%A{} != %A{}</code> I still see it as an acceptable tradeoff. Also, “blast radius” is controllable: you accept this tradeoff <em>explicitly</em> when prefer <code>defdynstruct</code> over <code>defstruct</code>.</p>
<aside class="quote no-group" data-username="a-maze-d" data-post="16" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/a-maze-d/48/31720_2.png" class="avatar"> a-maze-d:</div>
<blockquote>
<p>don’t surprise</p>
</blockquote>
</aside>
<p>The fact that <code>default: DateTime.utc_today()</code> is resolved at compile time actually also a surprise of a similar level. In my experience people constantly do this mistake. By using <code>defdynstruct</code> you replace one surprise with another, you do not increase overall amount of surprises (but I agree we increase variety).</p>
<p>Did I change how you see the problem? =)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377404" 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/runtime-calculated-default-values-for-structs/73189/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-377404" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377404"
                     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="377406" data-post-id="377406">
  <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>Tbh I disagree with the idea of <code>Repo.insert(%Reminder{})</code> needing to support dynamic defaults as well. Elixir is very much about being explicit. If you need your data to come from side effects I expect the code to tell me. <code>%Reminder{} |&gt; with_default_target_datetime() |&gt; Repo.insert()</code> is a lot better code than <code>Repo.insert(%Reminder{})</code> automatically messing around with struct fields.</p>
<p>You’re argueing that struct defaults being a compile time thing prevent libraries from introducing dynamic field defaults. I’d counter that with dynamic defaults being something you want to have an explicit api for and once you do there’s no longer any limitation. I don’t expect ecto ever wanted to provide you with a dynamic defaults feature to begin with.</p>
<p>In the end your argument comes down to “I want to introduce dynamically calculated default values without changing my codebase” – not a great argument imo, such a change should be made explicit by changing 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="377406" data-batch-url="/posts/batch_likers">
                        7
                      </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/runtime-calculated-default-values-for-structs/73189/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-377406" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377406"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="377407" data-post-id="377407">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ffloyd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/120/10538_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ffloyd
                    <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">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="20" data-topic="73189">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>such a change should be made explicit by changing code.</p>
</blockquote>
</aside>
<p>I think this is the root point of misalignment between us. I believe that in practice this particular explicitness only makes development more expensive, and makes code more complex and harder to support without real benefits. But there cannot be a theoretical proof for this.</p>
<p>Let’s wait for more feedback then!</p>
<p>Meanwhile I’m curious, what would be you idea of implementing dynamic default with Ecto? Patching all the functions that uses schema or can have this schema module as an argument? Or do I miss something more clever?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="377407" 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/runtime-calculated-default-values-for-structs/73189/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-377407" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="377407"
                     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/73189/load_more?page=3">Load more posts (20 remaining)</a>
</div></template></turbo-stream>