4 ms·
Testing if(null) inside my code always makes me feel like I've been punched in the face. Why should my code have to be on the lookout for bad parameters all of
by pq0ak2nnd 8y ago
Testing if(null) inside my code always makes me feel like I've been punched in the face. Why should my code have to be on the lookout for bad parameters all of the time? But on the other hand, my code should be on the lookout for bad parameters all of the time. Advice?
- projektfu 8y agoIf it's not an interface, then it is probably correct to crash when called incorrectly. Problems should be found early on. If it is an interface, you may need special processing. A clear way of doing this is to do the sanity checking in the interface method and then pass to a module-private method that does the work. Internal logic that calls the same method can bypass the sanity check.