views:

27

answers:

1

i'm setting up a custom class that accepts some Number parameters, but i need to limit those parameters and would like to know the best way of doing so.

currently, i'm simply calling if statements, and throwing an error if the number is above or below what's accepted. for example, there is a parameter that accepts and angle, but only between 0 and 90. in the case i've typed it as a uint so now i only have to check to see if it's above 90. there's also a parameter Number typed parameter that only accepts values between the range of 0.0 and 1.0.

is my method of using if statements and throwing erros the usual way of filtering parameters?

+2  A: 

Yes. The only way to get around this is to use the type system, e.g. create an AcuteAngle class that can only contain a number between 0 and 90. However, for what you're doing, it's better to just have if statements.

Your only other option is to silently clip inputs to the desirable range (for example, angle = angle % 90;). The official AS libraries tend to use this approach more often than not, but they're not terribly consistent.

Ender
I agree - there's no particular substitute for documenting what the function expects to receive, and deciding whether it should throw errors if it receives something else.
fenomas