Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
I really like doing this, but sometimes, when looking at the code really quick, in those languages that use the ! operator, I've found myself doing functions like isNotEmpty() so that I don't overlook the ! by mistake.
Kotlin's standard library has methods like isNotBlank() and isNotEmpty() as part of the String class that showcase this.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Tip to prevent this from happening in the future: Extract your if logic into its own function.
Instead of:
Write:
This has the additional benefits of making your logic reusable and also making your if statements more readable.
Cheers!
I really like doing this, but sometimes, when looking at the code really quick, in those languages that use the
!
operator, I've found myself doing functions likeisNotEmpty()
so that I don't overlook the!
by mistake.Kotlin's standard library has methods like
isNotBlank()
andisNotEmpty()
as part of theString
class that showcase this.Ramda has a function called
complement
that can help you build these functions.Believe it or not, I did exactly that and still managed to miss the
not
the first time around.Haha awesome! We have all been there.