Skip to content

explicit check for true? #383

Answered by jongpie
rmccu asked this question in Q&A
Oct 3, 2022 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

This is purely a stylistic choice that I've made for this repo, because I think explicitly specifying true or false helps with readability.

When I originally first started working on this repo years ago, I didn't follow that convention, I originally used the style you're referring to of if (someMap.containsKey(key)). But over the last several years, some of the teams I've worked on have found that during code reviews, some developers would misread conditions like if (someMap.containsKey(key)) and if (!someMap.containsKey(key)) because the ! can be easily overlooked. By switching to using if (someMap.containsKey(key) == true) and if (someMap.containsKey(key) == false), we found we had fewe…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@rmccu
Comment options

@jongpie
Comment options

Answer selected by jongpie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants