Latest Tweets:

Minor Suggestion: Unless.nil? - Down with double negatives

This is a very small tip aimed for people to clean up their code-base and remove some of the double negatives.

Often I shall see:

unless @user.nil?

The issue with this is approach is that unless is harder to read than if, then you have to mentally process the #nil?

The other approach is:

if @user

However, for a lot of people this is not explicit enough. I find that too few know about #present? method

if @user.present?

#present? is literally the opposite of #blank? and thus checks if it is not nil? or if it is not empty?

Hopefully with this small tidbit of knowledge, you can clean up your code and make it easier to read.