I use asserts a lot, to implement pre-conditions as well as post-conditions. (e.g. the verb LUCheck in http://www.jsoftware.com/jwiki/Essays/LU_Decomposition )
Asserts have advantages over your proposed technique: - It's clearer what asserts are doing. - It's possible to turn asserts on and off (9!:34 and 9!:35). On the other hand, asserts require the use of explicit definition. Both techniques are better than comments because they use a much more effective language (J instead of English). ----- Original Message ----- From: "Miller, Raul D" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Wednesday, April 19, 2006 6:04 AM Subject: [Jprogramming] constraint idioms Often, a programmer may have "type restrictions" in mind, when developing code. Here, the code is only relevant for some domain, and often the domain supported by J's primitives does not match this conceptual domain. When the conceptual domain is narrower than the real domain, it can sometimes be useful to express the conceptual domain in the code. This can be done through assert, but sometimes there are other ways of dealing with this issue. For example: i. [ ,&{. or -: [ ,&{. Both of these verbs are functionally equivalent to built-ins for some domain, but experience domain errors where the built ins do not. For example: '' (-: [ ,&{.) i.0 |domain error | '' (-:[,&{.)i.0 (Contrast this example with -: *. *.&{.) Of course, domain errors aren't the only constraints that might be useful in expressing a programmer's intent. Length errors, and so on can also be used. And, finally, although I've shown examples here where the constraints are applied to primitives, this technique is far more useful when applied to a derived verb. The point, after all, is to document the domain of some derived verb. This can help isolate problems when building a large application. (I'm of the opinion that documentation and executable code are two facets of the same concept. This becomes more true with high level languages, but could be true even with machine languages.) ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
