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: volker::nitsch::gmail::com at: 19-Jan-2005 16:33

On Wed, 19 Jan 2005 19:17:54 +0800, PeterWAWood <[pwawood--mango--net--my]> 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? >
No. 1) its longer. if it would be good, we would have a shortcut :) 2) this func [b [date!]] is the shortcut. 3) there are two types of fails: such which regulary happens(none!), and such which should never happen(error!). Thats why 'find returns none: often we want to know if something exists. 'read throws an error when file is missing: we rarely are prepared to deal with 'none instead of file-content. This keeps the code shorter, avoids continuing with broken data, and is simply smart: "hey coder, you forgot a file ;)". If the function-coder specifies a certain type, it means something. And passing something else is an coding-error. And the computer should be helpfull to do the right thing: decide if coder made error or did expect failing. In statically typing he does that conservative: if it could be wrong, it is wrong. in dynamically typing he flags only when he is really sure its wrong: at runtime with real data. but he checks. there is always 'attempt if you really may to call with wrong args: if attempt[to-integer ask "only numbers"][print "hohoho"] ;)
> Regards > > Peter > > -- > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.296 / Virus Database: 265.7.0 - Release Date: 17/01/2005 > > -- > To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject. >
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler