3 ms·
Nils are typed initial values, that should be clear from the existence of nil slices. Don't check nil on an interface type. Check in compress(), where a concret
by pishpash 6y ago
Nils are typed initial values, that should be clear from the existence of nil slices. Don't check nil on an interface type. Check in compress(), where a concrete type is established.
- gher-shyu3i 6y agoAnd implement that check in each and every function that has a receiver? That sounds like a recipe for bad performance (unnecessary branching), as well as unnecessary readability affects.
- pishpash 6y agoNot necessarily. It's suggested as a way to maintain the typing decision the original parent made, but which itself is undesirable. The pattern can be changed to, func main() { var c Compressor // signal do nothing DoCompress(c) c = &GZipComprosser{} // normal call DoCompress(c) }