Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ruby, should we always use "&&", "||" instead of "and", "or" unless for special situations? [closed]

Is it true that in most cases, in Ruby, it is best to use &&, || instead of and, or, unless it is some special situations.

I think one of Ruby's design principles is to have least surprises as possible, so using and, or or actually have some surprises... such as and not having a higher precedence than or, while && has a higher precedence than ||.

So I think in most cases, use &&, ||. In know in some special situations, it may require using and, or, but I think if those are intermixed with &&, ||, sooner or later it may create bugs when your coworkers who started in Ruby not so long ago need to edit your code.

like image 302
nonopolarity Avatar asked Sep 29 '10 21:09

nonopolarity


People also ask

Can I wear ruby everyday?

Yes, rubies are strong enough to withstand the wear and tear of everyday life.

Which finger is best for ruby ring?

Most astrologers recommend wearing the ruby ring on the ring finger of the right hand. Always remember to buy the gemstone from a reliable and certified source.

In which finger Manik should be wear?

The best finger to adorn the Ruby/Manik gemstone is the ring finger. The ring finger is popularly known as Anamika in Sanskrit. The Mount of Sun also called as Apollo is located just below the ring finger/Sun finger.

Who should not wear a ruby?

Who should not wear ruby gemstones? Taurus, Virgo, Capricorn, Aquarius, Libra, Capricorn, and Pisces ascendants should never wear rubies. This is because of the Sun's position and its enmity with these planetary positions.


1 Answers

Yes. Relying on and and or for boolean logic is a good way to introduce subtle bugs into your application.

They do have a place, though. They are a safe and readable option when used as control flow operators.

redirect_to root_url and return

I basically felt the way you did until I read this excellent blog post.

like image 184
Raphomet Avatar answered Sep 27 '22 21:09

Raphomet