<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 1/11/12 10:19 PM, Zabrane Mickael wrote:
<blockquote
cite="mid:CF5EFA30-A906-4E3B-A76D-EBB7D47257FA@gmail.com"
type="cite">Hi guys,
<div><br>
</div>
<div>Any Erlang library to simply <b>DbC</b> (à la Eiffel)?</div>
<div><br>
</div>
</blockquote>
I tend to just do:<br>
<br>
foo(Args) when GuardArgs -><br>
true = assert_precondition(Args),<br>
Result = ...<br>
true = assert_postcondition(Result),<br>
Result.<br>
<br>
Where GuardArgs protects the inbound arguments as much as possible.
The basic idea is that if your assumptions are not satisfied, you
crash before you begin doing bad stuff. As long as your functions
are pure, this works well. Also note that in many cases, providing
such pre/post-conditions actually strengthens the dialyzer quite a
bit since it uses the information to narrow down the valid
control-flow/data-flow paths in the code.<br>
<br>
That said, I am not consistent in writing code like this. I tend to
assert certain situations now and then, especially if the code has
proven to be tricky. In fact, if you look at typical erlang code,<br>
<br>
{ok, R} = ...<br>
<br>
is such an assertion. It protects the caller by asserting that a
certain operation succeeded. I'll recommend code be built around
this and then handling the crashes properly.<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Jesper Louis Andersen
Erlang Solutions Ltd., Copenhagen, DK</pre>
</body>
</html>