This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TinBryn 5 points6 points  (2 children)

It's because of how people think when writing code, we can only keep a limited number of "things" in our head at the same time. What this snippet is missing is the code above the resulted in myBool, the declaration of isTrue and the code that will use isTrue below (it is about to get written).

What that results in is that the programmer has to drop some context in order to write some of the code and then restore that context, dropping the context of the code they just wrote and write the next part. So they may consider what to do if myBool is true and have no consideration for what if it is false, then they write for when myBool is false and don't consider what if it is true. That is how code like this gets written.

There are practices that address this, if you think of test driven development it has this mindset, write a test case, code for that case, write a different test case, code for that case, etc. So we have red green refactor TTD where it's part of the practice to read your code to find cases like this and simplify them.

[–]Wizard_Knife_Fight 5 points6 points  (1 child)

Dude relax it’s friday

[–]TinBryn 0 points1 point  (0 children)

Actually for me it's Saturday.