It's always a good practice to test arguments in a function before function real processing begins.
But is that true for internal functions and interfaces? My boss(my tech lead) told me that you don't need to check for those things in internal interfaces, because the front end is always filtering them out.
So is that true, suppose a protocol, and when the protocol have many layers, and think that protocol is our internal protocol so is it okay to ignore those checks just because we only use that protocol internally?
But is that true for internal functions and interfaces ? My boss( my tech lead ) told me that you don't need to check for those things in internal interfaces, because the front end is always filtering them out.
Your boss is right insofar that this should be the frontends code responsibility and it makes no sense to do checks again and again (which hurts performance).
Probably the best practice is to use assert()
for parameter checks. So you don't have to rely on the frontends functionality during debugging and testing phase, but the checks will be removed for production code.
One thing I personally dislike with the assert()
approach is, that it's very debugging unfriendly.
It's way easier to catch an exception and check the call stack to see who the culprit was. Maybe the better idea regarding this is to write your own kind of assert()
macro, which doesn't call abort()
, but throws an appropriate exception. Same as the original assert()
that could be erased from production code.