In the interest of DRY, sanity checking should be within the subrountine/function. This is also a good defensive coding strategy (don't trust what is passed to you).
This is essential when writing a library or API.
This doesn't mean sanity checking cannot be done in the caller as well.
--
You received this message because you are subscribed to
the "Pick and MultiValue Databases" group.
To post, email to: mvd...@googlegroups.com
To unsubscribe, email to: mvdbms+un...@googlegroups.com
For more options, visit http://groups.google.com/group/mvdbms
The goal is to put sanity checking wherever it's most performant
I dunno.
Checking variables in the subroutine is inefficient, you could be
checking them multiple times. On the other hand, it's guaranteed safe,
the subroutine either returns a valid result, or fails cleanly.
Checking the variables as they come into the program is most efficient,
but a lot of grunt work and easily missed/forgotten/ignored. You don't
really want to sanity-check the contents of every record as you read it
:-( And it doesn't catch somewhere inside the program doing something
stupid and corrupting a variable.
Horses for courses.
Cheers,
Wol
> This particular question came up in another programming group and I was wondering what the take on it is by MV people. The question being, "Do you do your sanity checking on variables passed to a subroutine or function within that subroutine/function or before the variables are passed to it?"
>
> Examples of such "sanity checking" would be asserting things such as variable assignment, value, range, etc.
(apologies Kevin P - I hadn't realised my mail client had picked up your direct email rather than the list address)
If I was to give the 'ideal' view it would be to check in the called simply because it's the last place you can make sure you're not pushing cruft in to the database. However, a lot of our code is web or J2SE based and it makes sense to put a layer of error checking in the client process simply to offer a quicker turnaround of errors to the end user.
The upshot is that our server layer tends to check relational stuff like missing order numbers, customers on stop etc and the UI tends to check the basic stuff like is there a customer code there, are numbers numeric. The API and server side doesn't then replicate these checks.
Of course, the difference for me is that I have full and exclusive control over both ends of the model. If I was writing APIs for consumption for the general public as well as my own dedicated UIs, I would take a different approach with a more robust checking regime on the server.
Off to band rehearsal now...
--
David Morris
e: da...@brassedoff.net
blog: http://www.brassedoff.net | twitter: @brassedoff
.... I have not (yet) worked in an organisation where any kind of design rule is mandated - it is left up to the individual programmer and therefore subject to knowledge, experience and whimsy.