Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
burke
on Dec 13, 2022
|
parent
|
context
|
favorite
| on:
Read this post ‘unless’ you’re not a Ruby develope...
On this note: I’m sad ruby style guides generally ban “and” and “or”.
raise(“a long error string”) unless valid
This reads much worse, when the string pushes the line near max width, than:
valid or raise(“..
Of course it’s another idiom to learn but it’s not a difficult one when used simply.
klodolph
on Dec 13, 2022
|
next
[–]
That’s a very Perl idiom, did you previously write Perl?
burke
on Dec 14, 2022
|
parent
|
next
[–]
No, I just think for all ruby is bought into these guard clauses, it's sad that we generally reject the feature that allows putting either the condition or the consequence first, depending on which reads better.
graywh
on Dec 13, 2022
|
prev
[–]
the 2nd form implicitly returns the value of valid if it's truthy and nil if it's falsey; the 1st form always returns nil
burke
on Dec 14, 2022
|
parent
[–]
Indeed, but the return value of a guard clause shouldn't be important!
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: