In this discussion, _adrian_g and patroza debate the pros and cons of using effectful defaults and encoding defaults within schemas when working with data entities such as users, especially in the context of the Effect-TS library.
Key points:
Effectful Defaults: _adrian_g advocates for using effectful defaults, such as setting createdAt using a Clock during encoding. This approach encapsulates defaults within a schema, simplifying operations like persisting data.
Encoding vs. Entity Construction: patroza opposes the idea of encoding defaults, suggesting entity construction should ensure a fully initialized state, like setting createdAt at instantiation, not encoding. He prefers entities to be self-contained and not reliant on external factors like database operations.
Code First Philosophy: patroza emphasizes a "code first" approach, where database or framework concerns (such as default values) should not dictate code structure. He prefers deterministic and self-contained entity creation without relying on defaults added during encoding or persistence.
Inconsistent State Avoidance: patroza argues against having optional fields like createdAt, as it implies entities might exist in an inconsistent state.
Compatibility with Effect-TS: _adrian_g desires features like effectful constructors and defaults within the Effect-TS library, which would integrate well with Effect behaviors like controlled date-time handling.
Alternative Perspectives: There’s a recognition that while patroza prefers immediate consistency in entity states, other developers, including Tim from the Effect-TS community, apply a database-managed default strategy during encoding.
Throughout the discussion, _adrian_g and patroza consider different perspectives on handling entity state and defaults, with an understanding that their preferences reflect broader architectural choices in software design.
Summary
In this discussion, _adrian_g and patroza debate the pros and cons of using effectful defaults and encoding defaults within schemas when working with data entities such as users, especially in the context of the Effect-TS library.
Key points:
Effectful Defaults: _adrian_g advocates for using effectful defaults, such as setting
createdAt
using a Clock during encoding. This approach encapsulates defaults within a schema, simplifying operations like persisting data.Encoding vs. Entity Construction: patroza opposes the idea of encoding defaults, suggesting entity construction should ensure a fully initialized state, like setting
createdAt
at instantiation, not encoding. He prefers entities to be self-contained and not reliant on external factors like database operations.Code First Philosophy: patroza emphasizes a "code first" approach, where database or framework concerns (such as default values) should not dictate code structure. He prefers deterministic and self-contained entity creation without relying on defaults added during encoding or persistence.
Inconsistent State Avoidance: patroza argues against having optional fields like
createdAt
, as it implies entities might exist in an inconsistent state.Compatibility with Effect-TS: _adrian_g desires features like effectful constructors and defaults within the Effect-TS library, which would integrate well with Effect behaviors like controlled date-time handling.
Alternative Perspectives: There’s a recognition that while patroza prefers immediate consistency in entity states, other developers, including Tim from the Effect-TS community, apply a database-managed default strategy during encoding.
Throughout the discussion, _adrian_g and patroza consider different perspectives on handling entity state and defaults, with an understanding that their preferences reflect broader architectural choices in software design.
Discord thread
https://discord.com/channels/795981131316985866/1304719283263246400