Say I have some function that I may or may not want to execute during a particular run of the code, and this function also takes some argument that is passed in as a parameter at runtime. Is there some guidance as to whether a second variable to enable/disable the execution of the function is warranted, or is a "special value" of the argument just as good? I like the idea of reducing the number of parameters but I can understand how the former might be more readable.
For example, consider a 'Delay' function (which we may or may not want to run and) which accepts 1 floating point argument for the length of the delay. We can then check first that the argument-parameter is positive, and if it is not, we can not bother calling the function at all. Is this bad code?
I generally write in C/C++ if that matters.
Aucun commentaire:
Enregistrer un commentaire