Early return
Early return is a design patter that combines with the happy-path design pattern. When a function deviates from the happy path, we include a return inside the deviation so that the function interrupts.
1if x <= 0 {
2 fmt.Println("Nope, x is zero or negative")
3 return false
4}
It’s clear that if the function gets past this point, the condition must have been false, or we would have returned already.
This often makes else
statements pointless
References
#return #basics #programming #conditional #if #golang #control #flow #statement