Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Vladislav Trotsenko
Vladislav Trotsenko
9,291 Points

Using the negation operator, reverse the logic in the boolean statement.

Why I can't use unless instead if !(condition). What is more beautiful???

unless car_speed > speed_limit

vs

if !(car_speed > speed_limit)

Ugly coding detected.

2 Answers

Vladislav Trotsenko
Vladislav Trotsenko
9,291 Points

I'm always use unless if it possible and make my code more readable. Cheers!

Ari Misha
Ari Misha
19,323 Points

Hiya there! Always use unless instead of if !(something). The latter one might create a bug if you've like nested if-elsif-else code blocks. Not only unless prevents 'em same bugs but it also makes it easier to read for human sets of eyes. Being said that, try avoiding if-else blocks ad replace 'em with ternary operators for good practices. I hope it helped!

~ Ari