Design by contract in tinymail

I finished wrapping the API launchers of tinymail‘s core abstraction library (libtinymail) with require and ensure sections, like Eiffel’s design by contract clauses. Unlike in Eiffel you can’t weaken them in tinymail, you can only strengthen them. I didn’t use nana or ‘DBC for C’ for this, just assertions that wrap the function pointer invocation of the interface’s class struct.

The benefit is that it’s not in the body of the implementation, but rather at the interface’s level: If DBC is enabled and your implementation doesn’t fulfill the ensure clause, then the application will abort. To put it in another way: all implementations must fulfill the full contract of the interfaces that they implement. Also must the client code that uses the interface fulfill the requires clause. So any client code that calls an API yet doesn’t fulfill the input contract, makes the application abort itself (if DBC checking is enabled).

As usual, I try to practice what I preach, here’s the documentation on both using the contracts (enabling the checks) and creating your own ones while doing development for and with tinymail.