[CLJ-1141] Allow pre and post-conditions in defprotocol and deftype macros Created: 02/Jan/13 Updated: 07/Jan/13
|Affects Version/s:||Release 1.4|
Dos not matter.
The fn special form and the defn macro allow pre- and post-conditions. It would be nice if one could use that conditions also in method declarations of the defprotocol and deftype macro.
Currently I use the extend function as workaround where one can specify the methods using a map of keyword-name and fn special form.
|Comment by Michael Drogalis [ 06/Jan/13 6:22 PM ]|
Using :pre and :post, IMO, isn't a good idea. Handling assertions is a two part game. The mechanism needs to account for both detection and reaction, and the latter is missing.
This isn't a perfect work-around, as it's a little verbose, but using Dire might work better than using extend. In addition, you get the "reaction" functionality that's missing from :pre and :post
Example for protocol preconditions: https://gist.github.com/4471276
|Comment by Alexander Kiel [ 07/Jan/13 11:52 AM ]|
@Michael I read your gist and the README of Dire. I think the supervision concept of Erlang has it's places but I don't like it for pre- and post-conditions. For me, such conditions have two proposes:
To support my first point, your pre- and post-conditions are just lexical too far away from the actual function definition. For the second point: I think in the case of violations the program should just crash. One could maybe wrap some part of the program with one of your exception supervisors handling an AssertionError. But I don't think that handling pre- and post-condition violations for individual functions is a good thing.
|Comment by Michael Drogalis [ 07/Jan/13 5:28 PM ]|
@Alexander Indeed, your points are correct. Dire is meant to be exactly what you described. Lexically removed from application logic, and opportunity to recover from crashing. That was my best shot at aiding your needs quickly, anyway.