Even as an industry dev I'll still nearly write this when I'm on auto pilot. The only thing that's changed is I've gotten faster at noticing when I do it. Nowadays I'll notice it just as I start to write the value True!
This is what I was going to say. I start with some debug output or other code in one of the conditions, then at some point realize I've removed it and I have an Embarrassing Pattern in my code.
I feel like it’s a very natural pattern to end up with: I wrote down the if statement because I was sure something needs to be checked, and I haven’t yet figured out that just passing the checks value is what I want to do after the check.
Like others have said, the function's return being checked here is ambiguous. It might not be returning a bool, so this is probably okay. But in a lot of cases, the function is more clearly named, so the pattern of just writing return is_foo(bar) is both neat and clear
You should cast it either way for readability. Even if login always returns a bool, as a reader you wouldn't know unless you dig deeper (into the login function).
View all comments
356
u/PooSham Jan 23 '23
This is a very common pattern by beginners.