Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
tallanvor
on Dec 28, 2012
|
parent
|
context
|
favorite
| on:
IF-less programming
Whether or not the second example represents a syntactic improvement is more of a personal preference. Personally, I find the first example more readable when quickly scanning code.
jbrains
on Dec 28, 2012
[–]
Yes, but that's probably a matter of familiarity over clarity. This is a perfect time to use the irrationally-dreaded ternary operator.
param = object.property.nil? ? default_value : object.property
Verbose, although less so, but reveals intent almost perfectly. Would be better if the colon were "else" or "otherwise".
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: