Beginning Ruby

I decided a few weeks ago to pick up a new language. The choice was being between python and ruby. My day to day is php & js, so this is all coming from that angle.


I’d like to play around with tools like tc and stashboard. I’ve heard with python, there’s often only one way to do things - this has some appeal. But python seems to be transitioning right now from 2 to 3. Also, I don’t have fond memories of the last time I dipped my toe in the python pool - the shallow end mind you. Though I suspect homebrew will make it easier next time around. And I’ll be honest - the whole whitespace thing is a bit of a turnoff.


The whole ruby ecosystem is very appealing. My experience with gems to date has been pretty smooth. I use some gems via command line. It would be good to be able to hack on some of them. I’m jealous of services like heroku. In the web domain, ruby seems to offer a lot of solutions to problems that matter to me. Not that PHP doesn’t always have equivalent solutions - just that with ruby, it seems like a lot of the friction has been removed.

Ruby it is.

I’ve been learning ruby over the last few weeks. I used the humble little ruby book as my tutor. Basically put in about 30 mins a day on a semi-regular basis, and was done in about three weeks.

Overall, I was happy with the book. Once in a while I would encounter an example that didn’t work - but those were just boss battles :) When I hit a broken example, at that point I had the info required to solve it. If you’re already experienced with coding you’ll be able to skim some portions.

Some initial ruby impressions:

I totally get why people go gaga over ruby - especially if you come in straight from php land. For me it wasn’t the whole angels singing, double rainbow experience, but I think thats mainly due to my javascript experience. So I’ve already had some of those wow moments that you might get coming straight from php to ruby.

$ is reserved for globals, so you hardly see those around. When glancing at ruby code, I thought the heavy use of the pipe | would bother me, but in the end it really didn’t.

No ; After a few weeks of ruby, I began to resent that I had to use the ; daily. Though oddly it bothers me more in php than js.

Losing return?

In ruby, return is implied in many cases. I don’t know if I’ll be able to get out of the habit of being explicit and using return, especially in the immediate future. I’d hate to get in the habit of leaving out return, and when switching between langs, keep forgetting it.

Proc vs lambda. fight!

My initial reaction to Proc and lambda is that I lean towards lambda. I favour explicitness these days. Proc seems to lend itself to side effect bugs, especially for a newb. A return in a proc will break out of the calling method as well.

Maybe more valuable in frameworks, where you can accept variable args? That would be one good reason for using proc over lambda. I’m sure as I read through other people’s code, or with more ruby xp, I’ll see some use. One liners? Performance reasons? bueller?… bueller?…

Love unless

The readability is another big plus. Simple things - unless instead of if !=. Readability is one of those things that’s easy to dismiss, until you get hooked on it.

Really liking statement modifiers. Being able to just append a condition to a statement is really nice.

Inevitably, i find myself writing initially in longform,

if(!File.exists?(filename)) {, "w")

but each pass it gets smaller, till you realize you can just write something like, "w") unless File.exists?(filename)

Yield looks interesting. I’m curious to see how I use it.

Anyhow, my first ruby script - downloads your theme file from posterous, and saves it locally.

Next on the ruby reading list - Ruby Best Practices. I suspect I’ll do a skim through first, and a deeper reading once I have some ruby under my belt.