[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Constraints patch - help?
- From: Asko Kauppi <askok@...>
- Date: Mon, 23 Oct 2006 21:38:28 +0300
For local variables, because assert needs to be there N times, a
constraint is given just once and applies throughout that variable's
lifespan (checked at every assignment).
I am a heavy user of assert, or ASSUME as I like to alias it. That's
not going anywhere, as if I were in position to change the language
we love, to begin with...
Rici Lake kirjoitti 23.10.2006 kello 21.33:
On 23-Oct-06, at 1:11 PM, Asko Kauppi wrote:
The issue is, in larger programs its really benefitial to have the
_option_ of using type constraints on your variables, values, and
return values. Doing them integrated with the syntax simply hides
them more from the eye than doing 'assert' everywhere.
But why hide them? assert is a perfectly good way of making it
clear what the function expects:
function extract(str, i, j)
assert(isNumber(i) and i > 0 and i <= #str)
assert(isNumber(j) and j >= i and j <= #str)
local outside = str:sub(1, i) .. str:sub(j+1)
local inside = str:sub(i, j)
assert(#outside + #inside == #str)
return inside, outside