21 Dec '13, 11pm

Clearer Conditionals using De Morgan's Laws

Clearer Conditionals using De Morgan's Laws Gabe Berke-Williams December 20, 2013 refactoring Ever seen a hard-to-parse conditional like this? def allow_access_to_site? ! (signed_out? && untrusted_ip?) end Let's use De Morgan's Laws to clean it up and see who actually has access to our site. De Morgan's Laws Whoa, who's this De Morgan guy? Augustus De Morgan , in addition to looking like a 19th-century John C. Reilly , formulated two important rules of logical inference. You can check out the formal definition on the Wikipedia page , but here they are in Ruby code: # One !(a && b) == !a || !b # Two !(a || b) == !a && !b Well hey, it looks like we can use these on our gnarly conditional above. Let's try it. Law-abiding Ruby code Recall that the original conditional was ! (signed_out? && untrusted_ip?) . Let's use the second law and puzzle it out. # Original ! (signed_out? &...

Full article: http://robots.thoughtbot.com/clearer-conditionals-using-d...

Tweets

Clearer Conditionals using De Morgan's Laws

robots.thoughtbot.com 20 Dec '13, 5pm

Clearer Conditionals using De Morgan's Laws Gabe Berke-Williams December 20, 2013 refactoring Ever seen a hard-to-parse co...

How to Extract an Intention-Revealing Name Usin...

robots.thoughtbot.com 21 Dec '13, 4pm

How to Extract an Intention-Revealing Name Using Vim Joe Ferris May 02, 2012 vim refactoring This method has a magic numbe...

[Princessa's Diary] My Journey to Clearer Vision (Part 2)

[Princessa's Diary] My Journey to Clearer Visio...

sabrina.sg 21 Dec '13, 2am

Do you remember my story with astigmatism from my last post ? Well, let me share the embarrassing situations that my uncor...