Search This Blog

October 30, 2011

Vim for Rails Developer

Every person gives feedback based on his understanding of things which is dependant on his level of skills at that point in time. For the reader of this post, who is interested in knowing my background to better evaluate my feedback, I have elaborated in brief my history of experience in the RoR world of application development.

After spending about 10 months in my first JRuby on Rails-2,  two-developer all-chaotic first non-pairing project, where I was using RubyMine as IDE for all practical development purposes, I resolved to try out a new IDE in my next Rails gig. Folks at ThoughtWorks are in the habit of experimenting and trying out different IDEs. And hey, I was no exception ;) - prior to RubyMine, I tried Vim and Aptana RadRails, but for whatever reason I loved RubyMine, perhaps because I was too familiar with this one by virtue of my experience of using IntelliJ in Java projects.

As decided I did choose a new IDE when I moved on to my second RoR3 gig and it was Vim. Why Vim? Well, apart from it being extremely lightweight when compared to its counter-parts, I seriously wanted to get a hang of this IDE, as many RoR developers at our office either use TextMate or Vim (by stats more Vim fans). Okay so did I step into this very small and demanding project of just two developers (including me) that were notably enough not pairing (again!). What does that mean? It means I have to constantly explore to figure out the stuff that is required to become more and more conversant and productive with Vim (atleast as much I am with RubyMine). If you have gone through my experience you'll understand how steep a learning curve it is to get an appreciation of Vim for Rails productivity (even while learning Rails 3, argh!).

Now, I have moved on to my third RoR3 gig with 3-4 dev-pairs (ho-ho pairing again, after real long time!), where-in I guess all are Vim-ites. Its been a couple of days, and I see people use many productive plugins for Vim. Delighted!, my learning curve is going to get better.

In the mean time, I had requested Ben Orenstein, for a free copy of screen cast titled, "Vim for Rails Developers" that he authored. In return, I promised to write a candid review of his screen cast on my blog. I fulfill my promise with this blog post wherein I share my thoughts/experience of the said screencast. Now, the way I share my thoughts is by dissecting the portions of screen cast, and tell you what to expect from each of it. [pause] So, in the mentioned screencast, Ben has covered the following sections in bold:

Fast Typing:
  • Do you think, 80 words per minute is okay? Listen to him.
  • => How this site helps the enthusiast hit Bens's objective of "Speed with ********"

Vim Cheat sheet:
  • => I have many a times visited and downloaded this cheat-sheet from this site, but didn't really care to read it seriously. His talk I guess insisted well on what to look out for in this cheat sheet :)

Dvorak Simplified Keyboard
  • Learn to touch type.
  • I haven't heard this anytime before. I gotta know about this in this screen cast.
  • This is the only section that did not fascinate me, perhaps because I did not see him demonstrate its usefulness.

  • An intro on how to use it. He gave a real good shot at it, helping me understand that he did his best given the size of this huge plugin. Keep digging and you get more and more wealth of short-cuts! 
  • If you haven't used this plugin, his intro will seed the interest in you to try and have fun with this plugin.
  • Try this in your Vim command-line: :help rails => for rails-vim documentaion          

Snipmate: Mac's Textmate style snippets for Vim
  • It supports Rails
  • Where to look for your favorite language's snippets that snipmate supports [Note: ~/vim/snippets/]                
  • How to add your own snippet

The power of Tags
  • Exuberant CTAGS: CTags creates an index on where the class, methods, instances are defined. This helps the developer big-time in jumping from say, method usage to its definition. Intelli-sense of sorts, eh!
  • How to use CTags?
  • How CTags help?

  • Get it right. Its Ack, not awk! Its a grep replacement tool, designed for programmers. Can't believe the funda? Well, I too didn't until I watched him play in this screencast.

Quick one-offs    
  • Bunch of other enlightening surprises... :) By the time you reach here, you won't feel like skipping this section, for you'll quickly come to an understanding that this is not some miscellaneous stuff but the quick wins that you get to learn while you are playing with Vim.

For many, "seeing is believing". And I fall very much in that category. Thus, this screencast had a very good impact on me and so shall it on you ;) You can't ask for more in a screencast that is approximately 37 minutes long.

I'll heartily give him a 4.5/5 as rating for this screencast, for the good breadth and fair depth in content that he has both covered and demo-ed, in a manner that inspired me to kick myself harder to learn and get used to the stuffs/tools that he mentioned.

Thanks to Ben, for an awesome introduction through live demo to the various tools that he uses for his every-day rails programming. Personally though, I wish wish wish, he touched upon the other productivity plugins too, if he were to use any. Don't know if I'm being greedy here!

Lastly, if you wish to watch this screen-cast, and that you are put up in Chennai, don't miss the DevCamp,Chennai happening this November 19th at ThoughtWorks Technologies Ltd, Ascendas IT Park, Chennai, Tamil Nadu, India. This screencast is making an entry, and if voted for by many (as like any other in-person session), it will be put up. Come vote, watch and get enlightened!

October 21, 2011

Leveraging Subject in RSpec - A rough cut!

Do you use subject in RSpec? This blog post intends to help you get better with RSpec's subject. The better way to learn things is by way of an example; even better if we see a bad example and see how we can progressively improve it.

The better way to write the above test is as below:

Further refactoring the above code snippet, it can be compacted to below, although I hate to do this. I prefer to tests/specs being an utter no-brainer to read quickly and get the idea:

Finally the ideal way of testing the above scenario and the like would be to employ RSpec's subject as below:

If after reading all this you were to wish it be more leaner, then you should consider shoulda. Will blog about it's marriage with RSpec sooner ;) Until then see how snappier the above code becomes with the use of shoulda matchers. Hooray!!!

SQL Logging in Rails Console IRB

In order to quickly find the SQL queries that are fired against the DB, while you are playing on the Rails Console, all you need to do is set ActiveRecord's Logger to STDOUT as below:

>>ActiveRecord::Base.logger =

Custom finders and SQL Injections

Everyone writes bad code. The most awful and potentially very dangerous ones that cannot just cannot sit in the commit-able code are the badly written raw SQL queries or even your API code that can give leeway to SQL Injections or SQLi.

[ERROR] couchapp error: You aren't in a couchapp.

Every CouchApp must have a .couchapprc file in the application directory. This file is a JSON object which contains configuration parameters that the command-line app uses to build and push your CouchApp.

The couchapp generate and couchapp init commands create a default version of this file for you.

If you don't have a .couchapprc file, couchapp will display the dreaded couchapp error: You aren't in a couchapp message.