IntelliSense is a feature in the Visual Studio IDE that saves you a hell of a lot of typing and makes APIs discoverable. A common question/concern/phobia among .NET developers is how can Ruby development be productive without this feature? I am currently making the transition to Ruby myself. I have found that the combination of the powerful features of TextMate, quick feedback from the IRB, and the Ruby language reduce your dependence on IntelliSense. In this first post I discuss TextMate.
TextMate
Some Ruby IDEs such as JetBrains RubyMine do have Visual Studio style IntelliSense, but the majority of Ruby developers use TextMate as their primary editor. This has two features that give you 50% of what IntelliSense does: Completion and Snippets. (Other popular Ruby editors such as Emacs and Vim have similar features.)
Completion
Completion works as follows: if you start typing a word and press the ESC key, TextMate will attempt to complete the word if it has appeared previously in the file. For example if I have a Ruby file like the following:
and I press ESC after the p, TextMate will expand the p to print, as print has appeared previously in the file
Pressing ESC again will cycle through other potential matches. This is simplistic compared to auto-complete in Visual Studio (as TextMate lacks any type information about the code) but it does save a lot of typing.
Snippets
Snippets generate commonly used Ruby and API structures quickly. Typically you type the first 3 letters of a structure and then press TAB. For example, pressing def and TAB will generate a function definition:
You can install Bundles (TextMate extension packages) to add snippets for popular frameworks such as Rails or RSpec. For example, typing vl and TAB generates the following Rails code:
validates_length_of :attribute, :within => 3..20, :message => "must be present"
This is neat as it also helps you discover information about the API.
Other features
TextMate also has a help shortcut (CTRL + H) that looks up the API documenation on any method you highlight. Code Navigation is pretty powerful too. You can jump around files in a project (CMD + T) and between methods in a file (CMD + SHIFT + T) easily. RubyAMP is a powerful TextMate bundle that expands the Completion feature to include all the files in a project.
Next time
Next time I will discuss how the Ruby language itself, the APIs, and the IRB further lessen the dependence on IntelliSense.
Nice article Jason, timely for me as I’m starting to learn rails development. Part of the frustration of learning is not knowing what the available methods are. Looking forward to more installments.
I am trying to resist textmate as I don’t want to be tied to a propriety text editor on a single propriety platform, I am using emacs for everything.
A good starting point for useful ruby/rails stuff on emacs is
http://appsintheopen.com/articles/1-setting-up-emacs-for-rails-development
Some of the guys are using the emacs starter kit
https://github.com/technomancy/emacs-starter-kit
I started my emacs journey before I found the kit so am not using it except as a list of potentially useful packages.
I think for clojure dev emacs is a clear win and hope
https://code.google.com/p/yasnippet/
and
https://github.com/defunkt/textmate.el
will give me most of what textmate has in emacs.
Emacs can do a context aware IntelliSense for python so maybe able to do it for ruby too (I’m still experimenting)
I use http://tromey.com/elpa/ to manage 3rd party packages in emacs and use http://aquamacs.org/ on OSX.
Tom
Yeah I’m using Emacs too for Clojure stuff and its definitely the bee knees. The learning curve is quite steep but it is really powerful. The keyboard shortcuts are a bit too much though. I find my hand going claw like after a few hours in it.
I need to try out VIM next before settling on the one true editor.
This is not even close to 50% of what I am used to using Intellisense force. Code completion is nice, but a million text editors can do that (though not as intelligently as Intellisense). The major features I’m missing in my day-to-day in Ruby are: F12 (Go To Definition), XML documentation comments (e.g. “/// “) that show up in the method tooltips (along with overloads and parameters), and a debugger that allows me to mouse-hover any variable in the code and see its contents (having to type “next” “finish” a million times in the console is painful as hell).
-force +for