Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: A question of function interface design

From: andreas:bolka:gmx at: 19-Jan-2005 12:26

Wednesday, January 19, 2005, 12:17:54 PM, PeterWAWood wrote:
> I have started to question whether it is best to use Rebol's > automatic type checking of parameters or not when designing > functions. > If the type checking is used, calling a function with an incorrect type of > value causes a script error, eg: > >> a: func [b [date!]] [print b] > >> a 12345 > ** Script Error: a expected b argument of type: date > ** Near: a 12345 > However, if you don't use the built-in type checking, you can return a none! > value and give the caller the option (and responsibility) to deal with the > situation, eg: > >> a: func [b] [if type? b <> date! [return none]] > >> a 12345 > == none > Given that Rebol is not strongly typed, is the second of these > "idioms" the more appropriate?
While the latter has obvious flaws when dealing with functions that may validly return 'none, I can see no advantages whatsoever. If the caller wants to deal with the situation, why not simply use 'try ? For example a: func [b [date!]] [print b] if error? try [ a 12345 ] [ print "uh oh!" ] -- Best regards, Andreas