20
The Cost of Scattered Validation Logic | The frustrated developer
(blog.dotslashme.cc)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
I recently made a lua framework that constructs callable tables to be used as functions that take a table as a dictionary of named argument. The function declares a schema of parameters with associated required/default/optional policies that put their respective values through a transform and validation pipeline. A similar pipeline can also be put on the result to make explicit guarantees. Can also configure whether argument errors/violations should throw or return
results,errorshapeThe wrapped function recieves a table of processed arguments in a known state, while keeping that noise separate from the business logic. Also configurable at runtime with introspection, and param pipelines are immutable so they can be composed.
If that sounds like it introduces a lot of overhead, you're right! But 1) it's Lua and 2) omg is it so worth it when used properly. The UX is great; the callsite ergonomics, maintainability, and self-documenting nature is always what I felt was missing. Ships with & plays pretty well with type annotations too.
Anyways, that all makes it really convenient to know what's responsible for what, and encourages pretty safe designs.