Best Method of function parameter validation
Posted
by
Aglystas
on Programmers
See other posts from Programmers
or by Aglystas
Published on 2012-09-05T18:36:45Z
Indexed on
2012/09/05
21:49 UTC
Read the original article
Hit count: 260
I've been dabbling with the idea of creating my own CMS for the experience and because it would be fun to run my website off my own code base.
One of the decisions I keep coming back to is how best to validate incoming parameters for functions.
This is mostly in reference to simple data types since object validation would be quite a bit more complex.
At first I debated creating a naming convention that would contain information about what the parameters should be, (int, string, bool, etc) then I also figured I could create options to validate against. But then in every function I still need to run some sort of parameter validation that parses the parameter name to determine what the value can be then validate against it, granted this would be handled by passing the list of parameters to function but that still needs to happen and one of my goals is to remove the parameter validation from the function itself so that you can only have the actual function code that accomplishes the intended task without the additional code for validation.
Is there any good way of handling this, or is it so low level that typically parameter validation is just done at the start of the function call anyway, so I should stick with doing that.
© Programmers or respective owner