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

Does anyone here use assertions in anger in a web app? I sort of feel that frontend app that is jock-full with assertions and logs every assertion failure to a Sentry type service, would be much easier to get error-free. Almost to the point of needing significantly fewer unit tests, maybe. Is there any downsides to this approach? Do people do this?


Having worked on multiple systems that have done similar things to this, I'd fall on the side of no!

If you're not really careful the assertions will quickly obscure the actual logic (as does logging), a careless engineer can easily add a bad assertion and fill up your monitoring system, another careless engineer can write a complicated but broken assertion without any tests - they've all happened to me on multiple production systems.

Eiffel style pre and post conditions might be a solution as the assertions are kept away from the main code path in the method signatures - but at that point a modern statically typed language might give you more value (preferably with null safety and sum types).


My worst nightmare are abandoned assertions/errors. People logs them "just in case" and forget about them, years later you have huge volume in the logging system that nobody looks at.


Our UI at work is using typescript so these assertions aren't as important as they were in plain JS days.

However runtime types like io-ts are important in network calls since the HTTP client's return type is `unknown`.


Yeah, typescript obviates so many assertions that using assertions for things that the compiler can’t catch isn’t too burdensome.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

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

Search: