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

[REBOL] Re: [functions] Re: A question of function interface design

From: greggirwin::mindspring::com at: 19-Jan-2005 11:21

Peter, Michael, et al PW> I have started to question whether it is best to use Rebol's PW> automatic type checking of parameters or not when designing PW> functions. I do different things in different contexts. With other languages, I never exercised the same variety of styles that I do with REBOL, maybe because they didn't allow it. With REBOL, I can tailor the style to the need very easily, even in the same script. This may lead to a view that the code is inconsistent, but it can also work to make it clear what kind of code you're writing. For example, a function with no help string, no type checking, and no comments is probably not meant for re-use. A function that has types defined for some parameters, but not all, jumps out at me as "mostly designed". If it were "fully designed", it would have any-type! listed for those params. With no type set for only certain params, it's like I'm saying "I'm not sure yet what I may want to allow here". Being able to specify types and have REBOL check them for us is a wonderful thing, but every script may not need that level of control for every function. Use it when appropriate. I often define local functions, and keeping them short and sweet really helps. I'm only going to be calling them from the next ten lines of code, so there is strong context to assist in using them correctly. MB> I thought Rebol is strongly typed (but not statically) ... like a value MB> has always an assigned type. Correct. Values have types, variables don't. MB> Are there any comments regarding DBC being (un)useful for Rebol ? I think it could be useful in certain applications. Again, REBOL is very flexible and there will be times when tools like DbC *will* be helpful; for most little REBOL scripts it would be overkill. I've tinkered a bit with Eiffel, and built my own DbC system for VB, which I used a lot and did help me to catch things sometimes. I think it can work well in an OO context, where you may be integrating a lot of little pieces you didn't write, and you're maybe not sure how they behave. In REBOL I find I write more general predicate functions, though I did play with Maarten's DbC stuff a bit. How would DbC work with something like PARSE though? It's really only applicable at the function level. Something else to consider is how it would work when you're dealing with code as data and such. One of the great things about REBOL is that we can try these things out (AOP is another hot topic) and see where they're applicable. e.g. you may have some critical parts of an app that would really benefit from DbC, so you could write a little dialect for just that purpose, or use Maarten's just for those pieces. With Eiffel, and I found with VB once I wrote my framework for it, you tend to use DbC very heavily, whether it's really necessary or not. -- Gregg