Created
December 4, 2012 17:10
-
-
Save just3ws/4206356 to your computer and use it in GitHub Desktop.
Because Twitter eats whitespace...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The example I tweeted about preferring the more verbose if..then..else..end | |
# over ternary operations in Ruby got mangled by Twitter. | |
# So when my tweet showed everything on one line my message got muddled. | |
# The reformatting of my tweet also looked like I was trying to evaluate | |
# an expression that returned literally "true" or "false" which wasn't the case. | |
# What I wanted to show was that many people write IF/ELSE statements as | |
# ternary operations. | |
class MyContrivedExample; def self.i_am_true?; true; end; end | |
x = MyContrivedExample.i_am_true? ? "foo foo foo" : "bar bar bar" | |
# I like to write them as full IF/ELSE expressions | |
y = if MyContrivedExample.i_am_true? | |
then "foo foo foo" | |
else "bar bar bar" | |
end | |
# People tend to try to conserve horizontal space over vertical space. | |
# 1. Anything but the most trivial example becomes unreadable in a single | |
# line as the ":" operator usually ends up off screen. | |
# 2. Our eyes are trained to read lines very quickly over a lifetime of | |
# reading top-to-bottom and left-to-right (in western cultures). | |
# 3. Breaking the line and letting in some air (whitespace) then our eyes | |
# and brain get a break to make processing the logic easier. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment