News for hackers. Stuff that matters.
Re:Applying “make invalid states unrepresentable” by the-smug-one on Monday October 05, 2020 @07:13AM (#24686540)
You could always split your types into frontend and backend types where the backend ones are more open and the frontend ones are more restricted. I don't necessarily mean FE/BE as on the web. A lot of code is only interested in shuffling around data anyway, the shape is fairly uninteresting.
Re:Applying “make invalid states unrepresentable” by nemetroid on Monday October 05, 2020 @09:42AM (#24687683)
I would put it the other way around: make your basic representation restricted, but present a more permissive API. This way, the data model helps enforce your constraints, but you don't need to redesign the API when the requirements (inevitably) change.
Re:Applying “make invalid states unrepresentable” by dllthomas on Monday October 05, 2020 @07:18PM (#24693113)
If you make your front-end interface more complex than is needed to represent current data, you may save clients a migration in the future. But you force your clients to deal with the complexity right now, and you could wind up needing to change things in a different way in the future. Neither of these concerns clearly dominates all the time - it's a question of just how much effort you're saving them, just how likely various changes are, etc.

On the other hand, if you make your internal representation support more complexity than what you hand out to your users, there arises the question of how you simplify (probably lossily!) or break when you wind up with data that can't be expressed with the simpler interface. But you might well be saving yourself a costly data migration down the line. Also a decision with trade-offs that could potentially go either way.

Re:Applying “make invalid states unrepresentable” by gambler on Monday October 05, 2020 @12:07PM (#24688993)
Kind of like internal data/algorithms and external interface in OOP?