# Runtime-calculated default values for structs

**URL:** <https://forum.elixirforum.com/t/runtime-calculated-default-values-for-structs/73189>\
**Category:** Proposals: Ideas\
**Tags:** ecto, structs, oban, default\
**Created:** [November 4, 2025, 3:57pm UTC](https://forum.elixirforum.com/t/runtime-calculated-default-values-for-structs/73189 "2025-11-04T15:57:26Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![ffloyd](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ffloyd/32/10538_2.png) [@ffloyd](https://forum.elixirforum.com/u/ffloyd)\
**Post date:** [November 4, 2025, 6:20pm UTC](https://forum.elixirforum.com/t/runtime-calculated-default-values-for-structs/73189/11 "2025-11-04T18:20:38Z")

</div>

Yeah. Let me summarize:

1. Often engineers do `%Struct{}` for creating a new instance of a struct by default. There is no established tradition to create factory functions like in Golang.
2. Elixir allows to set only “static” defaults. So `%Struct{}` already has some implicitness, but at least it is “idempotent” after compilation.
3. For defining a dynamic default each place where `%Struct{}`, `struct(...)`, etc is used should be refactored.
  - In big codebases it can lead to inadequately expensive refactoring for just introducing a mere dynamic default.
  - creation of a struct can be inside library code so you may be not able to inject default value at all.

4. Cultural problem: libraries repeat “no dynamic defaults” restriction that does not makes developers life easier, usually opposite.
5. Such limitation is uncommon in other popular languages I can recall.

Original proposal solves mentioned problems, but breaks `%Struct{} == %Struct{}` behavior. But without breaking it we cannot make `%Struct{}` respect dynamic defaults. And without this we cannot make adding dynamic defaults cheap in big codebases.

❓ Might be loosing this behavior is acceptable sacrifice? Or we’re missing some smart move here?

---

_[View the full topic](https://forum.elixirforum.com/t/runtime-calculated-default-values-for-structs/73189)._
