Articles from 2008

 
 

CVS Shortcuts in Vim

Vim is an incredibly flexible text editor. I continue to be surprised by the number of strange things it’s capable of doing. For example, there is a crude Tetris clone available for Vim.

A bit more useful, though, is the cvsmenu script for Vim. This is a fairly polished plug-in that will allow you to do all of the basic CVS tasks from inside your text editor. The supported CVS commands are: add, diff, commit, update, status, shortstatus, localstatus, and revertchanges.

Since the plug-in is poorly documented, I thought that I would take this opportunity to explain how to use it.

Installation

In Ubuntu, this is pretty simple.

% sudo aptitude install vim-scripts

% vim-addons install cvsmenu

This will install the package and enable the plugin for your user.

Usage

I will assume that you already have a versioned source tree checked out on your system. Start by opening a file in this tree. You can open a diff view by typing “,cd”. Note: that’s comma, C, D.

The local revision is shown on the right, the remote revision is on the left. This is a bit backwards from the Eclipse and Netbeans way of doing things. Typing CTRL+W+W will move your cursor between the two revisions. I haven’t found an easy way to move a change to the right, but I would be interested in reader comments.

Here is an index of the commands. They may be documentation somewhere but I was only able to find them by looking at the plug-in source code.

  • ,ca - Add
  • ,cd - Diff
  • ,ci - Commit
  • ,cu - Update
  • ,cs - Status
  • ,ch - Short Status
  • ,cc - Local Status
  • ,cv - Revert Local Changes. The odd thing about this is that it only updates the file on disk. It doesn’t actually revert the changes in the open editor.

Modern IDEs do ease the pain of performing mundane versioning tasks such as merging. But, this is a nice alternative to those heavy-weight tools.

socialthing! and Prism on Ubuntu

A recent article on the socialthing! blog made me curious about setting up a site specific browser in Ubuntu.

This is a pretty simple thing to accomplish and it beats the heck out of the currently available Ubuntu twitter clients.

Start by installing the prism package.

компютриsudo aptitude install prism

You can then setup a new application by starting prism either from the command line or from the applications menu. Setup is pretty self-explanitory but here is a screenshot for good measure.

If your looking for a good socialthing! icon, you can find one here. Then launch your new app and voila!

You might also checkout prism-facebook, prism-google-mail, prism-google-reader, and prism-twitter.

Code Duplication

A while ago I fixed some obscure bugs in one of the search results pages of an enterprise application that I work on. I spent about four hours of focused development time refactoring and cleaning up some of the logic that handles the rendering and paging of the results. The new code worked well.

A couple of weeks later I found myself bug squashing on another search results page. As I dove into the code, I found a nagging sense of deja vu. This page had the same logic errors and mistakes as the page I had worked on weeks earlier. I found myself fixing the same bugs and performing the exact same refactorings as I had before.

I became more frustrated as I realized that the original author had copied all of the logic from the original page. Rather than extracting the common functionality to a reusable location, he took the lazy approach with copy and paste.

This kind of mistake is expensive. By duplicating the code, the cost of maintenance has doubled. Bugs must now be fixed in both places. Merging the common logic after the fact is more difficult than it would have been initially.

We have these wonderful object oriented languages. There are many ways to reuse code. Some of the following come to mind:

  • Two subclasses can share common functionality in a parent class.
  • Duplicated code can be moved into it’s own class. This can be done in a concrete class or via a static utility class.

There is a fine line between a generic flexible UI and a crappy one:

Got the Chocolate Raspberry Stout in the fermenter. I can't wait to taste it.

Just poured out 10 Liters of overly-carbonated, accidentally-alcoholic, plastic-flavored, homemade root beer. Lessons learned: 3!

Follow me on Twitter