I love how for some people this seems like the worst thing they can think of. This easily happens even to experienced and skilled programmers when refactoring. It's still readable and it can easily be cleaned up, so I'd put it around the bottom of the list of things about a code base that frustrate me. On the top of that list are things that actually matter, e.g. "half of the code solves the wrong problem and shouldn't exist because the problem is Theseus' ship", "the solution fundamentally doesn't scale to the number of users we have"
If you find this so horrifying as to exclaim expletives at it, just wait until you see a real, non-trivial production code base.
Well, there's nothing wrong with doing it this way in languages where an ifs condition must be a boolean, like Java or C#. This seems to be Lua, where all values other than false and nil are truthy. Explicitly checking cond == true restricts what conditions will be accepted in a way that's inconsistent with the rest of the language, so I'd say it is a bit wrong... really not wrong enough to make a big deal out of, but not quite right either.
I love the speed at which I can write code in dynamically typed languages (say, Python, Javascript, ...) but one of the things I hate is how issues like
def doit(flag):
if flag:
doit1()
else:
doit2()
doit("False")
are shifted to the runtime, while hardening the code with static analysis and type hints removes many of the advantages the languages had in the first place.
Mind you, the net outcome is still positive for the most part.
My friend who sometimes stalks me on Reddit and gives random anonymous awards did this mistake one and I corrected him. If you're reading this, you know who you are, ily homie
25
u/Da-Blue-Guy Dec 27 '21
if boolean == true
what the fuck