Hacker News new | ask | show | jobs
by balfebs 1270 days ago
The post assertions do look very similar to a unit test, but the pre assertions seem really useful; it can sometimes be difficult to know every code path that leads to your function, and though tools exist for this, assertions on inputs help you catch errors arising from unusual conditions.

This seems like it’s mostly syntactic sugar for assertions, keeping them at the interfaces of the function (in and out).

It can also be sometimes useful to have these conditions right there alongside the implementation and not just somewhere else in your unit tests.