<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <title>ScottHarvey.co</title>
 <link href="http://scottharvey.co/feed/" rel="self"/>
 <link href="http://scottharvey.co/"/>
 <updated>2012-04-16T04:32:34-07:00</updated>
 <id>http://scottharvey.co/</id>
 <author>
   <name>ScottHarvey.co</name>
   <email>scott@scottharvey.co</email>
 </author>

 
 <entry>
   <title>Getting Started With Vim</title>
   <link href="http://scottharvey.co/2012/04/getting-started-with-vim"/>
   <updated>2012-04-05T00:00:00-07:00</updated>
   <id>http://recursive-design.com/2012/04/getting-started-with-vim</id>
   <content type="html">&lt;p&gt;Learning to use Vim as your text editor is much like learning a new programming language, it&amp;#8217;s going to be slow going at first but once you become proficient it&amp;#8217;ll be a powerful addition to your coding tool belt.&lt;/p&gt;

&lt;h3 id='learning_the_basics'&gt;Learning the basics&lt;/h3&gt;

&lt;p&gt;To keep things simple I&amp;#8217;m not going to run you through the basics of installing Vim, for that you can check out the download and install instructions on the &lt;a href='http://www.vim.org/'&gt;vim.org&lt;/a&gt; site. &lt;a href='http://www.vim.org/download.php'&gt;http://www.vim.org/download.php&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before jumping in the deep end I strongly suggest you learn the basics first by spending some time going through the Vim tutorial. To get started switch over to your command line and type in the following to fire up the Vim tutor.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;vimtutor&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That tutorial is going to take you around 30 minutes to work through and will stop you from throwing your computer out the window when you actually start editing text in Vim. Make sure you follow along and try out everything as you read through and remember to be patient as you progress.&lt;/p&gt;

&lt;p&gt;After I had gone through the tutorial I would play around with Vim by editing single files for a while until I felt it was time to start using Vim for development work. One of the first features you&amp;#8217;ll be wanting is syntax highlighting which is one of the many features managed in your .vimrc file.&lt;/p&gt;

&lt;h3 id='maintaining_your_vimrc_file'&gt;Maintaining your .vimrc file&lt;/h3&gt;

&lt;p&gt;Your &lt;code&gt;~/.vimrc&lt;/code&gt; file is where you will store all of your customisations for your Vim development environment. If you trawl the internet you can find a wide range of example .vimrc files but &lt;em&gt;I highly recommend you start with an extremely simple file that you slowly build up as you hit roadblocks&lt;/em&gt; or need to do something more efficiently. Something like this should get you started:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;let mapleader = &amp;quot;,&amp;quot;

syntax enable                   &amp;quot; syntax highlighting
filetype plugin indent on       &amp;quot; load file type plugins + indentation
set nocompatible                &amp;quot; choose no compatibility with legacy vi
set encoding=utf-8              &amp;quot; character encoding
set showcmd                     &amp;quot; display incomplete commands

&amp;quot;&amp;quot; Whitespace
set tabstop=2 shiftwidth=2      &amp;quot; a tab is two spaces (or set this to 4)
set expandtab                   &amp;quot; use spaces, not tabs (optional)
set backspace=indent,eol,start  &amp;quot; backspace through everything in insert mode

&amp;quot;&amp;quot; Searching
set hlsearch                    &amp;quot; highlight matches
set incsearch                   &amp;quot; incremental searching
set ignorecase                  &amp;quot; searches are case insensitive...
set smartcase                   &amp;quot; ... unless they contain at least one capital letter&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To really get feel for Vim you should understand what each of those lines does and adjust them to suite your tastes. As you continue to use Vim your .vimrc will be changing fairly often especially in the beginning. I try to keep my file fairly small and maintainable and it&amp;#8217;s currently around 100 lines with comments.&lt;/p&gt;

&lt;h3 id='working_within_a_project'&gt;Working within a project&lt;/h3&gt;

&lt;p&gt;There are a few main players when it comes to moving around a project using Vim but for simplicity of use I recommend using &lt;a href='https://github.com/wincent/Command-T'&gt;CommandT&lt;/a&gt;. It can be a bit tricky to install and get running as it requires you have a version of Vim built with Ruby support but if you carefully read and follow the installation instructions you should be able to work it all out. Just remember to build the CommandT plugin using your system Ruby if you are using rvm to manage Ruby versions.&lt;/p&gt;

&lt;p&gt;Once installed CommandT allows you to quickly jump to files in the same way you do when using TextMate, just remember if you are using command line Vim you may need to hit &lt;code&gt;&amp;lt;Leader&amp;gt;t&lt;/code&gt; to use it instead of &lt;code&gt;Command+T&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='getting_ready_for_plugins'&gt;Getting ready for plugins&lt;/h3&gt;

&lt;p&gt;Now that you are hopefully comfortable editing files, customising your environment and working within a project let&amp;#8217;s step into the world of Vim plugins. To do this I suggest you follow along this excellent article by Tammer Saleh that goes through each step you need to follow to set-up an easy to maintain plugin environment.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://tammersaleh.com/posts/the-modern-vim-config-with-pathogen'&gt;The Modern Vim Config with Pathogen&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That article lists a lot of good plugins in the example code but as with your .vimrc file it&amp;#8217;s important to understand what each plugin does and how to use it. &lt;em&gt;Throwing other people&amp;#8217;s plugins and configurations into your Vim environment without understanding what it does is a sure path to frustration.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id='customising_your_environment'&gt;Customising your environment&lt;/h3&gt;

&lt;p&gt;I like to have a gook looking and easy to read development environment. In the past it was difficult to make Vim look as slick as other editors such as TextMate. But with the correct font choice, theme colours and a couple of plugins Vim can look as good (or better) and any editor out there. Here is a screen shot of how my editor looks at the time of writing this article.&lt;/p&gt;

&lt;p&gt;&lt;a href='/images/vim.png'&gt;&lt;img src='/images/vim_small.png' alt='MacVim screenshot' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everyone&amp;#8217;s taste is going to vary a bit when it comes to the look of their environment so play around for a bit and see if you can find a look and feel that will work for you. &lt;em&gt;Part of the fun with using Vim is customising everything so they look and work just the way you like them to.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id='making_the_switch'&gt;Making the switch&lt;/h3&gt;

&lt;p&gt;There are a couple of different schools of thought when it comes to making the switch to Vim. There&amp;#8217;s the cold turkey approach where you dive straight in and use Vim full time while you are learning it. There&amp;#8217;s the gradual approach where you use Vim and occasionally switch to another editor if you need to do more complicated work.&lt;/p&gt;

&lt;p&gt;Personally I went for a more gradual switch where I was using Vim at home for personal projects and then once I was happy with my efficiency I switched to using Vim for my contracting work. As with everything just play around until you find a system that suites you personally.&lt;/p&gt;

&lt;p&gt;Lastly if you are interested in seeing how I have my Vim set-up have a look through my dot files on Github.&lt;/p&gt;

&lt;p&gt;&lt;a href='https://github.com/scottharvey/dotfiles'&gt;https://github.com/scottharvey/dotfiles&lt;/a&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>When Not To Test</title>
   <link href="http://scottharvey.co/2012/04/when-not-to-test"/>
   <updated>2012-04-02T00:00:00-07:00</updated>
   <id>http://recursive-design.com/2012/04/when-not-to-test</id>
   <content type="html">&lt;p&gt;All code comes with a cost and your test suite is no different. Every line of code that you write needs to be maintained, reviewed and updated as your application evolves.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m a big fan of test first development but testing is a bit of an art form and part of the art is knowing when not to dogmatically follow the test first approach.&lt;/p&gt;

&lt;h3 id='quickly_prototyping_a_new_feature'&gt;Quickly prototyping a new feature&lt;/h3&gt;

&lt;p&gt;When putting together a new feature I generally like to start by putting together the interface first. This will involve throwing together some HTML, CSS and possibly Javascript for basic interactions.&lt;/p&gt;

&lt;p&gt;The code that gets written during this prototyping phase will rarely get put together using a test first approach because I&amp;#8217;m just not sure what I&amp;#8217;m building and in all likelihood it&amp;#8217;s going to change once I get some feedback.&lt;/p&gt;

&lt;p&gt;I also occasionally forgo the test first approach when building out a new class and I&amp;#8217;m still uncertain as to how I want to interact with it or possibly still trying to determine how it&amp;#8217;s going to fit into the system as whole. Once I gain more confidence in what I&amp;#8217;m building I&amp;#8217;ll often put the code to one side and then write it again starting with tests first.&lt;/p&gt;

&lt;h3 id='low_risk_code_that_doesnt_change_often'&gt;Low risk code that doesn&amp;#8217;t change often&lt;/h3&gt;

&lt;p&gt;Let&amp;#8217;s say for example that I have an admin area where I can login and update a list of product categories. The code that powers this part of the system has been written hundreds of times before and this time around there&amp;#8217;s nothing new being added.&lt;/p&gt;

&lt;p&gt;If you are writing this with Rails and using Gems such as Formtastic and InheritedResources there is almost no code to write once you&amp;#8217;ve setup your models, views and controllers. Considering this is a non-public facing area of the site, the code is not going to change much and it isn&amp;#8217;t critical to the system I would be reluctant to test this much at all.&lt;/p&gt;

&lt;p&gt;In the end I may just write a green path integration test just to make sure I can visit the page and fill in the form but anything more than that is going to be overkill and just more code to maintain in the future.&lt;/p&gt;

&lt;h3 id='hacking_on_code_for_fun'&gt;Hacking on code for fun&lt;/h3&gt;

&lt;p&gt;Outside of the scenarios listed above the only other time that I&amp;#8217;m not testing is when I&amp;#8217;M just hacking some code together to try out a new library, language or technique. This code more often than not gets deleted or thrown into a Git repository for future reference.&lt;/p&gt;

&lt;p&gt;Overall you should be testing before writing code and you should be doing it often. Just remember that to every good rule there are good exceptions.&lt;/p&gt;</content>
 </entry>
 
 
</feed>
