Created
February 26, 2011 04:48
-
-
Save dbrady/844950 to your computer and use it in GitHub Desktop.
Semantically identical code, three idiomatic ways of expressing it
This file contains 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
# Coders from from C often like this style: | |
log status == OK ? "OK" : "PROBLEM" | |
log "All done." | |
# But since if returns a value in ruby, you can spell it out: | |
log if status == OK | |
"OK" | |
else | |
"PROBLEM" | |
end | |
log "All done." | |
# I favor this style, because it pushes the whole expression out and preserves the vertical registration of if/else/end | |
log if status == OK | |
"OK" | |
else | |
"PROBLEM" | |
end | |
log "All done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If we're still doing Ruby you don't need any of those semicolons:
works just fine.