5 ms·
11 ways of thinking! if not something: # Unhappy case return # Happy case
by nicwolff 3y ago
11 ways of thinking!
if not something:
# Unhappy case
return
# Happy case
- nickjj 3y agoYep, personally I think that's ok too. It's mainly avoiding the "if not else" pattern in 1 condition. I haven't met anyone who fully agrees that it's easier to read than "if happy else unhappy" or returning early with whatever condition makes sense for the function.
- Izkata 3y agoThis one specifically has a name, that if statement (including the early return) is a guard clause.