Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Re-framing the logic of the app can also help.

For example, in your example is there any situation where there is an invoice that has not been paid?

In the vast majority of shopping cart systems, that would be a hard NO. There would be an Order ID, for carts that have not yet been paid for, sure, but an Invoice ID only makes sense if the order has been fully paid for, and not at any stage previous to that.

As such, why have an Order Status at all? Have the mere presence of the Invoice ID be the flag that states the order has been paid for. As in: null = not paid, not null = paid.





For what it’s worth, this discussion is exactly what pushed me to experiment with a small runtime invariant helper for React/JS.

The idea wasn’t to replace good modeling or tests, but to fail early when real-world state temporarily drifts away from its intended shape (especially in async or legacy flows).

I put a small prototype here if anyone’s curious: https://github.com/vortexshadow678-hash/invariant-guard




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: