Hacker News new | past | comments | ask | show | jobs | submit login

I've read a lot of Ruby code over the years and never seen "if [..] then" used so much as in this (otherwise fun) piece. Have I just been lucky and it's actually more commonly used than I think? :)



You need "then" or a colon when compressing an if statement onto one line. My production code generally puts the test expression in trail (foo if bar) when things fit on one line and therefore I almost never use it.

It's in the blog piece because when talking about things resembling an English sentence, sometimes writing them on one line highlights the relationship.


Oh yeah, I see that, but it's in all but one of the multi-liners too. Not that I'm against the idea - it's just not something I've seen much of :)


I guess I was trying to be consistent. I'll fix the multi-liners. if it helps any, I forgot how to write a one line if with the test expression in head position and had to look it up.

Typical dreamer behaviour, can babble about anaphora but if asked to write an if expression on one line in a job interview would bomb out...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: