There is generally 2 types of function regarding your question:
Different programming language may have different conventions about the naming of both types. Take C++
as an example, one common naming is CHECK_XXX
for type 2 and IsXXX
for type 1.
Here is an example taken from a tutorial of the google-log library:
CHECK(fp->Write(x) == 4) << "Write failed!";
CHECK_NE(1, 2) << ": The world must be ending!";
Another example is the maktaba utility library for Vimscript
, where maktaba#value#IsXXX()
is used to test whether the argument is of a certain type while maktaba#ensure#IsXXX()
is used to ensure IsXXX
holds and throws an exception otherwise.
function! TakeAString(name)
" Ensure argument type is String.
let name = maktaba#ensure#IsString(a:name)
endfunction
if maktaba#value#IsString(name)
" Branch if name is a String.
echo name
endif
So here is the point: choose the one that suits your need best and name the function according to the convention of the language. In terms of use cases of both, roughly, use the type 2 to check pre-condition like argument type and use the type 1 in conditional statements.