3 ms·
You should check the nulls where you run the risk for panic. This is doubly true if your function is part of a library.
by mariusor 2y ago
You should check the nulls where you run the risk for panic. This is doubly true if your function is part of a library.
- enneff 2y agoIt depends. In this trivial case, what do you do if you find s == nil is true? You probably panic anyway. Unless you have some specific reason to panic with a different message to the default “nil pointer dereference” then there’s no point checking it.
- jfoudfwfayasd 2y agoIncorrect, it's a type system flaw.
- dwattttt 2y agoThe point is that you should check for null, then be able to represent the variable as something that can't be null. That way once you've checked it's not null (somewhere you're not forced to panic ideally), you can pass around the pointer & be confident you don't need to ever check it again.