Re:Ruby Tips Part 1
by ldubinets on Monday September 02, 2013 @01:44PM
(#6316201)
Ruby is neat! Except for this part:
[ Parent
| on HN ]
I'm a fan of:
while true do
puts 'lol'
end unless true
but seriously, I like postconditions. they're also handy for encoding intent, if you have a pattern of the left-hand-side being the primary logic flow.
Re:Ruby Tips Part 1
by xentronium on Monday September 02, 2013 @03:08PM
(#6316593)
Is it a statement-modifier 'unless' that bothers you? `return ... unless ...` is kind of idiomatic way of returning early in the function. You get used to this shortcut ridiculously fast.
Wait, why? Try to read it aloud and it will make sense. I've seen lot's of hard and confusing syntax but this is not one of them. And I'm not a Ruby developer.
Post conditions are odd if you're not used to them, but once you start to mentally allow for them, they're really quite nice.
Ah, seems everybody misunderstood my comment (not hard to see why). It's not the post conditions that bother me, its the dynamic typing! In my opinion, ruby's duck typing really only works until you actually need it.