Thursday, December 25, 2008

The day Merb joined Rails

It's a historic day in history of Rails (and Merb). Eyepoppingly shocking, Merb 2 has a new name -- Rails 3. Yes! Merb is being merged into Rails 3!

DHH and Yehuda Katz announced it almost simultaneously. 96% people are positive about the merger. If you belong to 4%, David has an answer for you.

Ezra explains how Merb is undergoing a rebirth. This merger would hopefully break the myth that Rails is a monolith. Interesting to see community putting an end to drama and coming together.

Friday, December 19, 2008

Programming has evolved

When I look at the recent advancements in Behaviour Driven Development in Rails, I tend to think that programming has really evolved. Not in terms of advanced data structures and superior algorithms, but as a focus shift of intention.

Earlier the focus was the machine. Days are gone when we thought so much about saving an extra byte, trading code simplicity for speed. A compromise here, a saving there, ad infinitum.

The focus has definitely shifted to human understandability. Beauty of code now lies in its simplicity (some folks would argue that it always did, and they're right, but its more so apparent now).

First it was Ruby, then Rails, and now BDD frameworks like rSpec and Cucumber prove the point. Just have a look at these executable code examples.

animals = [ "Tiger", "Cow", "Python", "Horse" ]
animals.each do |animal|
puts animal + "is cool!"
#=> Tiger is cool! Cow is cool! ...
Does a C for loop or C++ iterator look more elegant?

class Project
belongs_to :portfolio
has_one :project_manager
has_many :milestones
has_and_belongs_to_many :categories
Code that you can just read, isn't it?

lambda {
}.should change(employee, :title).from("Mail Clerk").to("CEO")
Yes, that's a real executable example.

And now, Cucumber
Scenario: Search by topic
Given there are 240 courses where neither has the topic "biology"
And there are 3 courses A,B,C that each have "biology" as one of the topics
When I search for "biology"
Then I should see a the following courses:
| title |
| A |
| B |
| C |

More beautiful, more succinct, more concise. That's what programming has evolved to be.

Thursday, December 18, 2008

Git your branch name into your shell

I use git on my Ubuntu for my Rails projects, and very frequently I need to know what branch I'm working on right now.
If I can just get my shell to display the current local branch all the time in the prompt, it'd be a lot easier. I just found I could do so.

You need to modify the environment variable PS1 to show your current local git branch.

For me, it looks like this now.

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w [$(git branch 2>/dev/null| grep "\*" | cut -f 2 -d " ")]\$ '

And it renders out like

kazim@invincible:~/projects/aprioriate [refactoring]$

In short, you need to append the following to the PS1 string.

[$(git branch 2>/dev/null| grep "\*" | cut -f 2 -d " ")]\$

The redirection of stderr to /dev/null is required since it suppresses git error messages in case you're not inside a git directory.

Ugly though it may be, it works. And to make the PS1 persist, add the line into your ~/.bashrc file.

PS: I use bash. For zsh and others, its even easier to do this.