<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns:media="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom">
 
  <title>mcramm.com</title>
  <link href="http://mcramm.com/"/>
  <link type="application/atom+xml" rel="self" href="http://mcramm.com/atom.xml"/>
  <updated>2012-03-13T17:48:59-07:00</updated>
  <id>http://mcramm.com/</id>
  <author>
    <name>Michael Cramm</name>
    <email>mike@mcramm.com</email>
  </author>

  
  <entry>
    <id>http://mcramm.com/2012/01/27/watch-yourself</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2012/01/27/watch-yourself.html"/>
    <title>Watch Yourself</title>
    <updated>2012-01-27T00:00:00-08:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;p&gt;Every week since the new year started I&amp;#8217;ve been getting asked what my New Years resolutions were for 2012. My answer the first few times was the truth: &amp;#8220;I haven&amp;#8217;t decided yet.&amp;#8221; Almost magically, the focus will shift to the other person and they&amp;#8217;ll explain to me that this year they plan on being more active, do more travelling, etc. At this point my attention will wane my eyes will gloss over and the words &amp;#8220;Oh, nice!&amp;#8221; fall out.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve noticed that most people don&amp;#8217;t hit these kinds of goals and I can&amp;#8217;t tell if its because they&amp;#8217;re to vague, unrealistic, that the person is lazy, or some combination of the three. With me I know that I&amp;#8217;ll only hit my goals if they&amp;#8217;re A) specific and B) obtainable. &amp;#8220;I want to be more active&amp;#8221; is a nice goal, and one that every sunlight bereft developer should strive for, but isn&amp;#8217;t specific enough. &amp;#8220;I want to learn how to perform a frontside-180&amp;#8221; is pretty specific and completely obtainable for even for someone who has just started snowboarding.&lt;/p&gt;

&lt;p&gt;When I sat down to pick a resolution for this year, I wanted to pick something about myself professionally that could use some improvement. I made a list. A &lt;strong&gt;long, very scary&lt;/strong&gt; list that I&amp;#8217;ve since hidden under my bed and don&amp;#8217;t plan on looking at again until sometime mid-August. The list was good though, and it has definitely given me some stuff to think about. More importantly I was able to pull out a couple of resolutions from it that I are realistic enough, but will still require some diligence on my part in order to obtain.&lt;/p&gt;

&lt;h2 id='stop_and_think'&gt;Stop and Think&lt;/h2&gt;

&lt;p&gt;If I had to classify the first part of my career, I think I would label myself an &amp;#8220;Idealistic Hacker.&amp;#8221; When given a new problem, I would launch into an answer without thinking through the ramifications that came with it. I would typically look back at my newly minted solution and realise that it didn&amp;#8217;t &lt;em&gt;quite&lt;/em&gt; fit with the issue I was trying to solve. I would then spend more time hacking my hack until the requirements were met.&lt;/p&gt;

&lt;p&gt;Obviously this was a problem. It worked for a while until I realized that I was wasting a ton of time not only with getting the feature shipped, but trying to re-understand my solution on a return trip to the module 6 months later.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m the kind of guy who appreciates well designed code and loathes the ugly. I take pride in designing my code well because I know that it saves time for the next person who has to read it. I&amp;#8217;ve found through practice and experience that I can achieve my highest level of satisfaction when I&amp;#8217;ve taken the time to truly think about a problem before I sit down to solve it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is in essence what Rich Hicky talks about in a presentation he gave called &lt;a href='http://blip.tv/clojure/hammock-driven-development-4475586'&gt;Hammock Driven Development&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Undoubtedly there are times in our jobs where we aren&amp;#8217;t afforded the luxury of taking even a day to think through a problem, but we should be able to at least spare a few minutes to make sure we &lt;strong&gt;understand&lt;/strong&gt; the problem. I&amp;#8217;ve come up with two really obvious tactics to force myself to come up with good solutions. The first is to throw an idea at a colleague and see what they think. Small, two minute discussions about a problem has saved me boatloads of time when designing a solution. The second is to make sure I write my tests first.&lt;/p&gt;

&lt;h2 id='practice_tdd_everywhere'&gt;Practice TDD EVERYWHERE&lt;/h2&gt;

&lt;p&gt;TDD is something I&amp;#8217;ve been practicing on my own for a while now, but I haven&amp;#8217;t yet made the leap to using it full time at work. I don&amp;#8217;t really have an excuse for this. Most of my colleagues believe in the practice, and everyone is in favor of writing tests. I just tend to get to so bogged down with problems from all different angles that I spend more time writing my tests after I&amp;#8217;ve finished rather than before.&lt;/p&gt;

&lt;p&gt;I decided this needed to stop when I began working on a module that had no tests associated with it. My problem was trivial: a date value wasn&amp;#8217;t appearing on a client facing widget. The solution seemed simple enough. There was a &lt;code&gt;default_display_value&lt;/code&gt; attribute on the widget that wasn&amp;#8217;t being set during its creation so all I needed to do was add the correct date to the parameters being passed in. Alas, this appeared to do nothing and I spent the next hour following a maze of logic that only served to confirm that the code I was looking at had been hacked together.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve vowed since then to always write tests for any code I touch &lt;strong&gt;first&lt;/strong&gt;. I&amp;#8217;ll do this not only because I know it will result in better code, but that the next developer will be able to expand upon it without worrying about breaking whats there.&lt;/p&gt;

&lt;p&gt;By now you&amp;#8217;re probably wondering why I titled this post &amp;#8220;Watch Yourself&amp;#8221; and not &amp;#8220;Stop What You&amp;#8217;re Doing and Write Tests!&amp;#8221; To be honest, I originally set out to write something along those lines, but it felt overly preachy and has been done to death. I changed it to be more about myself and what I&amp;#8217;ve experienced. I know what works for me because I&amp;#8217;ve taken the time to look back at what I&amp;#8217;ve done, determine where I&amp;#8217;ve succeed, where I&amp;#8217;ve failed and try to improve myself professionally.&lt;/p&gt;

&lt;p&gt;You should too.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/12/18/tdd-in-node</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/12/18/tdd-in-node.html"/>
    <title>Tdd In Node</title>
    <updated>2011-12-18T00:00:00-08:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;p&gt;TDD is discipline that I&amp;#8217;ve been trying to master for a while now, and I&amp;#8217;ve been absorbing every blog post, talk, or book I can get my hands on. One thing thats key for me is to have some way to run my tests very quickly. Even better, the tests should run automatically whenever code in application files or tests changes.&lt;/p&gt;

&lt;p&gt;In Ruby, I have Guard. It works beautifully and does exactly what I need it to do. I spent the last week struggling to find something similar in NodeJs but didn&amp;#8217;t come up with anything I liked. I found it frustrating, because watching for events on files or directories is something that Node should be good at. In the end I settled on writing a simple Cakefile:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;    &lt;span class='no'&gt;CoffeeScript&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;coffee-script&amp;#39;&lt;/span&gt;

    &lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='nb'&gt;print&lt;/span&gt;&lt;span class='p'&gt;}&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;util&amp;#39;&lt;/span&gt;
    &lt;span class='nb'&gt;exec&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;require&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;child_process&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;exec&lt;/span&gt;
    &lt;span class='n'&gt;fs&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;fs&amp;#39;&lt;/span&gt;

    &lt;span class='c1'&gt;# ANSI Terminal Colors&lt;/span&gt;
    &lt;span class='n'&gt;green&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;\033[0;32m&amp;#39;&lt;/span&gt;
    &lt;span class='n'&gt;reset&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;\033[0m&amp;#39;&lt;/span&gt;
    &lt;span class='n'&gt;red&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;\033[0;31m&amp;#39;&lt;/span&gt;

    &lt;span class='n'&gt;log&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;message&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;color&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;explanation&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class='n'&gt;console&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;log&lt;/span&gt; &lt;span class='n'&gt;color&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='n'&gt;message&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='n'&gt;reset&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39; &amp;#39;&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;explanation&lt;/span&gt; &lt;span class='ow'&gt;or&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

    &lt;span class='n'&gt;compile&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;callback&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class='nb'&gt;exec&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;coffee -o js -c lib&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;error&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;stdout&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;stderr&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;error&lt;/span&gt; &lt;span class='n'&gt;is&lt;/span&gt; &lt;span class='n'&gt;null&lt;/span&gt;
                &lt;span class='n'&gt;log&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;compiled!&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;green&lt;/span&gt;
                &lt;span class='n'&gt;callback?&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
            &lt;span class='k'&gt;else&lt;/span&gt;
                &lt;span class='n'&gt;log&lt;/span&gt; &lt;span class='n'&gt;error&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;red&lt;/span&gt;

    &lt;span class='nb'&gt;test&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class='n'&gt;command&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;jasmine-node --coffee spec&amp;#39;&lt;/span&gt;

        &lt;span class='nb'&gt;exec&lt;/span&gt; &lt;span class='n'&gt;command&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;error&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;stdout&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;stderr&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;error&lt;/span&gt; &lt;span class='n'&gt;is&lt;/span&gt; &lt;span class='n'&gt;null&lt;/span&gt;
                &lt;span class='n'&gt;log&lt;/span&gt; &lt;span class='n'&gt;stdout&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;green&lt;/span&gt;
            &lt;span class='k'&gt;else&lt;/span&gt;
                &lt;span class='n'&gt;log&lt;/span&gt; &lt;span class='n'&gt;stdout&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;red&lt;/span&gt;

    &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;build&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;Compile the coffeescript into javascript&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class='n'&gt;compile&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;

    &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;test&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;Run the tests&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class='nb'&gt;test&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;

    &lt;span class='n'&gt;task&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;watch&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;Watch for file changes and compile into javascript&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class='n'&gt;fs&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;watch&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;spec&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;filename&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt; &lt;span class='nb'&gt;test&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
        &lt;span class='n'&gt;fs&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;watch&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;lib&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;event&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;filename&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='o'&gt;-&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;compile&lt;/span&gt; &lt;span class='nb'&gt;test&lt;/span&gt;

        &lt;span class='n'&gt;compile&lt;/span&gt; &lt;span class='nb'&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This file is pretty simple and contains three tasks: build, test and watch. Node has an easy way to watch for file system events on directories through &lt;code&gt;fs.watch &amp;lt;directory&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I tried a couple of testing libraries, but settled on &lt;a href='https://github.com/mhevery/jasmine-node'&gt;jasmine-node&lt;/a&gt; since I&amp;#8217;ve used it before.&lt;/p&gt;

&lt;p&gt;Now I can just run &lt;code&gt;cake watch&lt;/code&gt; and start writing code. Occasionally I&amp;#8217;ll stop and take a look at the other monitor to make sure everything is green. I used this process and ran through the classic &lt;a href='http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata'&gt;Bowling Game Kata&lt;/a&gt;. I also posted &lt;a href='https://github.com/mcramm/node_katas'&gt;the source&lt;/a&gt; on GitHub.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/12/06/vim-reboot-7</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/12/06/vim-reboot-7.html"/>
    <title>Vim Reboot 7</title>
    <updated>2011-12-06T00:00:00-08:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;h3 id='some_other_useful_plugins'&gt;Some other useful plugins&lt;/h3&gt;

&lt;p&gt;There are some other plugins remaining that I find quite useful, but don&amp;#8217;t need to do much configuration for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href='https://github.com/msanders/snipmate.vim'&gt;SnipMate&lt;/a&gt; - For quickly creating your own custom snippets.&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/tpope/vim-surround'&gt;Surround&lt;/a&gt; - For working with surrounding brackets. Need to change your &lt;code&gt;&amp;quot;&lt;/code&gt;&amp;#8217;s to &lt;code&gt;&amp;#39;&lt;/code&gt;&amp;#8217;s ? or &lt;code&gt;()&lt;/code&gt; to &lt;code&gt;[]&lt;/code&gt;? Use Surround.vim.&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/tpope/vim-unimpaired'&gt;Unimpared&lt;/a&gt; - Mappings for common operations.&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/scrooloose/nerdtree'&gt;NERD Tree&lt;/a&gt; - Sidebar that contains the structure of the current project. Useful for common file operations.&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/tpope/vim-endwise'&gt;Endwise&lt;/a&gt; - Adds the &amp;#8216;end&amp;#8217; keyword to certain structures automatically in Ruby.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each of these plugins can be installed by simply downloading the zip and unpacking it in your &lt;code&gt;~/.vim&lt;/code&gt; directory.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/11/27/vim-reboot-6</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/11/27/vim-reboot-6.html"/>
    <title>Vim Reboot 6</title>
    <updated>2011-11-27T00:00:00-08:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;h3 id='commandt'&gt;Command-T&lt;/h3&gt;

&lt;p&gt;I used &lt;a href='http://macromates.com/'&gt;Textmate&lt;/a&gt; when I first started learning Ruby/Rails and after I switched to Vim, I missed the ability to use the &lt;code&gt;&amp;lt;Cmd&amp;gt;-t&lt;/code&gt; hotkey to quickly open up new files. What was so great about it was that you could hit the hotkey and start typing the name of your file to filter the resulting list. Once you had filtered the list enough to have your file appear at the top, you just hit &lt;code&gt;&amp;lt;Enter&amp;gt;&lt;/code&gt; and the file would open as the active pane in Textmate.&lt;/p&gt;

&lt;p&gt;After a bit of research, I came across &lt;a href='http://www.vim.org/scripts/script.php?script_id=3025'&gt;Command-T&lt;/a&gt;. This plugin works in the exact same and can even be improved with some minor configuration.&lt;/p&gt;

&lt;p&gt;Installing this plugin is slightly more involved than others. First, download the &lt;code&gt;.vba&lt;/code&gt;, open it in vim and source it with &lt;code&gt;:so %&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You then need to install the C extension:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='nb'&gt;cd&lt;/span&gt; ~/.vim/ruby/command-t
ruby extconf.rb
make
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And the plugin will be installed! I would recommend doing the following configuration as well:&lt;/p&gt;

&lt;p&gt;From my &lt;code&gt;~/.vimrc&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='vim'&gt;&lt;span class='c'&gt;&amp;quot; Command-T configuration&lt;/span&gt;
&lt;span class='c'&gt;&amp;quot; Set the max height to 20 lines&lt;/span&gt;
&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='k'&gt;let&lt;/span&gt; g:CommandTMaxHeight&lt;span class='p'&gt;=&lt;/span&gt;&lt;span class='m'&gt;20&lt;/span&gt;
&lt;span class='c'&gt;&amp;quot; Show dotfiles like .gitignore, .rvmrc&lt;/span&gt;
&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='k'&gt;let&lt;/span&gt; g:CommandTAlwaysShowDotFiles&lt;span class='p'&gt;=&lt;/span&gt;&lt;span class='m'&gt;1&lt;/span&gt;
&lt;span class='c'&gt;&amp;quot; The maximum number of files to search through&lt;/span&gt;
&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='k'&gt;let&lt;/span&gt; g:CommandTMaxFiles&lt;span class='p'&gt;=&lt;/span&gt;&lt;span class='m'&gt;20000&lt;/span&gt;
&lt;span class='c'&gt;&amp;quot; Map ctrl-t to command-T since the meta key isn&amp;#39;t available when using&lt;/span&gt;
&lt;span class='c'&gt;&amp;quot; vim on the server&lt;/span&gt;
&lt;span class='p'&gt;:&lt;/span&gt;map &lt;span class='p'&gt;&amp;lt;&lt;/span&gt;C&lt;span class='p'&gt;-&lt;/span&gt;T&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; :CommandT&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;CR&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And from my &lt;code&gt;~/.gvimrc&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='vim'&gt;&lt;span class='c'&gt;&amp;quot; Set the mac meta key&lt;/span&gt;
macmenu &amp;amp;File.New\ Tab &lt;span class='nb'&gt;key&lt;/span&gt;&lt;span class='p'&gt;=&amp;lt;&lt;/span&gt;D&lt;span class='p'&gt;-&lt;/span&gt;T&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;
map &lt;span class='p'&gt;&amp;lt;&lt;/span&gt;D&lt;span class='p'&gt;-&lt;/span&gt;&lt;span class='k'&gt;t&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; :CommandT&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;CR&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;
imap &lt;span class='p'&gt;&amp;lt;&lt;/span&gt;D&lt;span class='p'&gt;-&lt;/span&gt;&lt;span class='k'&gt;t&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;&amp;lt;&lt;/span&gt;Esc&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;:CommandT&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;CR&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When you&amp;#8217;re in a project, you can now hit &lt;code&gt;&amp;lt;Cmd&amp;gt;-t&lt;/code&gt; and start typing the name of the file you wish to edit. You can scroll up and down the list by using &lt;code&gt;&amp;lt;Ctrl&amp;gt;-j&lt;/code&gt; and &lt;code&gt;&amp;lt;Ctrl&amp;gt;-k&lt;/code&gt; respectively. To open a file, just hit &lt;code&gt;&amp;lt;Enter&amp;gt;&lt;/code&gt;. You can also open a file in a new vertical split by doing &lt;code&gt;&amp;lt;Ctrl&amp;gt;-v&lt;/code&gt;, or in a new tab by doing &lt;code&gt;&amp;lt;Ctrl&amp;gt;-t&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id='setting_the_default_leader_key'&gt;Setting the default leader key&lt;/h3&gt;

&lt;p&gt;It might be a good idea at this point to update the default leader key used to prepend any custom mappings you create. I always set mine to &lt;code&gt;,&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;~/.vimrc&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='vim'&gt;&lt;span class='c'&gt;&amp;quot; Set the leader&lt;/span&gt;
&lt;span class='k'&gt;let&lt;/span&gt; mapleader &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='c'&gt;&amp;quot;,&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now you can do something like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='vim'&gt;&lt;span class='c'&gt;&amp;quot; toggle line numbering on and off&lt;/span&gt;
map &lt;span class='p'&gt;&amp;lt;&lt;/span&gt;Leader&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;&lt;span class='k'&gt;n&lt;/span&gt; :&lt;span class='k'&gt;set&lt;/span&gt; &lt;span class='k'&gt;number&lt;/span&gt;&lt;span class='p'&gt;!&amp;lt;&lt;/span&gt;CR&lt;span class='p'&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When you hit &lt;code&gt;,n&lt;/code&gt; in vim, line numbers will be toggle on and off.&lt;/p&gt;

&lt;h3 id='commandts_buffer_list'&gt;Command-T&amp;#8217;s buffer list&lt;/h3&gt;

&lt;p&gt;Now that we have the default leader setup, we can take advantage of Command-T&amp;#8217;s built-in buffer manager. If you don&amp;#8217;t know what buffers are in vim then you should take a look at &lt;a href='http://vim.wikia.com/wiki/Vim_buffer_FAQ'&gt;this page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After you&amp;#8217;ve opened/closed a few files, you hit &lt;code&gt;,b&lt;/code&gt; to see a list of any buffers open in the current session. In some cases, this can actually be quicker than using the standard Command-T interface.&lt;/p&gt;

&lt;p&gt;There is an alternative to Command-T&amp;#8217;s buffer window called &lt;a href='https://github.com/sjbach/lusty'&gt;LustyJuggler&lt;/a&gt;. I would recommend giving it a try if you&amp;#8217;re not fond of how Command-T manages buffers.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/11/14/vim-reboot-5</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/11/14/vim-reboot-5.html"/>
    <title>Vim Reboot 5</title>
    <updated>2011-11-14T00:00:00-08:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;h3 id='plugins_in_vim'&gt;Plugins in VIM&lt;/h3&gt;

&lt;p&gt;Vim plugins can be enabled in a variety of ways. Sometimes all you need to do is copy the &lt;em&gt;plugin&lt;/em&gt;.vim to &lt;code&gt;~/.vim/plugin&lt;/code&gt;. Other times the plugin comes packaged as a &lt;code&gt;.vba&lt;/code&gt; file that you need to open in vim and source by executing &lt;code&gt;:so %&lt;/code&gt;. In any case, you should always read the plugin&amp;#8217;s README &lt;em&gt;first&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Some people have gone out of there way to write vim plugins that make installing &lt;em&gt;other&lt;/em&gt; plugins even easier. I have come across two such plugins in my research.&lt;/p&gt;

&lt;p&gt;&lt;a href='https://github.com/tpope/vim-pathogen'&gt;Pathogen&lt;/a&gt; was created by &lt;a href='http://tbaggery.com/'&gt;Tim Pope&lt;/a&gt; and has been around for a while. A couple colleagues of mine use it and seem to really like it.&lt;/p&gt;

&lt;p&gt;&lt;a href='https://github.com/gmarik/vundle'&gt;Vundle&lt;/a&gt; was inspired by &lt;a href='http://gembundler.com/'&gt;Bundler&amp;#8217;s&lt;/a&gt; method of keeping track of rubygems for projects.&lt;/p&gt;

&lt;p&gt;For the sake of these posts, I&amp;#8217;m going to stick with the &amp;#8220;vanilla&amp;#8221; method of installing plugins. If you&amp;#8217;re curious though, I would recommend trying out both of those plugin management solutions as they can make organizing your plugins much easier.&lt;/p&gt;

&lt;h3 id='tab_completion'&gt;Tab Completion&lt;/h3&gt;

&lt;p&gt;I got to admit, all of the setup done in the previous posts was incredibly frustrating without tab completion. &lt;a href='http://www.vim.org/scripts/script.php?script_id=1643'&gt;SuperTab&lt;/a&gt; is the best solution I&amp;#8217;ve found. The plugin comes as a &lt;code&gt;.vba&lt;/code&gt; file, which means installing it requires you to open the file up and type &lt;code&gt;:so %&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now when you are in your editor and hit &lt;code&gt;tab&lt;/code&gt;, a handy dandy list of all possible matches will appear:&lt;/p&gt;
&lt;img src='https://lh6.googleusercontent.com/-A-lO289m2tA/TqdWJZrED8I/AAAAAAAAAt4/aONsAKE-uk0/s173/Screen%2Bshot%2B2011-10-25%2Bat%2B6.35.35%2BPM.png' width='200' /&gt;
&lt;h3 id='nerd_commenter'&gt;Nerd Commenter&lt;/h3&gt;

&lt;p&gt;Commenting lines in and out can get pretty arduous if you do it a lot. With &lt;a href='http://www.vim.org/scripts/script.php?script_id=1218'&gt;Nerd Commenter&lt;/a&gt;, you can comment a line in or out by doing &lt;code&gt;&amp;lt;Leader&amp;gt;ci&lt;/code&gt;. Make sure that you have &lt;code&gt;filetype plugin indent on&lt;/code&gt; in your &lt;code&gt;~/.vimrc&lt;/code&gt;, as the plugin will use the appropriate comments for the language you&amp;#8217;re in. There are a couple of other commenting formats available with the plugin, so you should look through the vimscripts page and try a few commands out.&lt;/p&gt;

&lt;p&gt;To install, simply download the &lt;code&gt;.zip&lt;/code&gt; file to &lt;code&gt;~/.vim/&lt;/code&gt;, and unpack it.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/10/29/rubys-load-path</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/10/29/rubys-load-path.html"/>
    <title>Ruby's Load Path</title>
    <updated>2011-10-29T00:00:00-07:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;p&gt;One thing that always tripped me up when I first started writing my own gems was how to properly require other files when the files were relative to the current file&amp;#8217;s path. Let&amp;#8217;s say you have your classes laid out like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    app.rb
    lib/
        myclass.rb
        anotherclass.rb
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;How would you require those two files in &lt;code&gt;lib&lt;/code&gt;? I quickly became used to doing something like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;    &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;dirname&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='bp'&gt;__FILE__&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;lib&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;myclass&amp;#39;&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;dirname&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='bp'&gt;__FILE__&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;lib&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;anotherclass&amp;#39;&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Which works, but has a lot of duplication. All I really care about is the name of the file I&amp;#8217;m requiring, and that&amp;#8217;s all the way at the end of the line.&lt;/p&gt;

&lt;p&gt;In quicker, smaller projects, it was okay since I only ever needed to require one file at a time. On larger projects though, I began to do the following:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;    &lt;span class='n'&gt;path_to_lib&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt;  &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;dirname&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='bp'&gt;__FILE__&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;lib&amp;#39;&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='n'&gt;path_to_lib&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;myclass&amp;#39;&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This was better but it still felt like I was doing something unnecessary. Finally one day I was frustrated enough to look into what &lt;code&gt;require&lt;/code&gt; actually did. How does Ruby know where to look when requiring a gem? If I want to use the &lt;a href='http://rubydoc.info/gems/typhoeus/0.3.2/frames'&gt;Typhoeus&lt;/a&gt; library, I can just say &lt;code&gt;require &amp;#39;typhoeus&amp;#39;&lt;/code&gt;; I don&amp;#8217;t need to specify the full path to its location.&lt;/p&gt;

&lt;p&gt;Sounds like its time to check out Ruby&amp;#8217;s &lt;a href='http://www.ruby-doc.org/core-1.9.2/Kernel.html#method-i-require'&gt;Kernel&lt;/a&gt; module.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ruby tries to load the library named &lt;em&gt;string&lt;/em&gt;, returning &lt;em&gt;true&lt;/em&gt; if successful. If the filename does not resolve to an absolute path, it will be searched for in the directories listed in &lt;code&gt;$:&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Makes sense. All I should need to do is add the subdirectory I want to require to load to the path that Ruby scans through. Kernel&amp;#8217;s rdoc says that the path(s) are stored in &lt;code&gt;$:&lt;/code&gt;. Let&amp;#8217;s see whats in there:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;    &lt;span class='nb'&gt;p&lt;/span&gt; &lt;span class='vg'&gt;$:&lt;/span&gt;  &lt;span class='c1'&gt;# =&amp;gt; [&amp;quot;/Library/Ruby/Site/1.8&amp;quot;, ... ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Looks like its just an array of paths. I should be able to simply add a path to the end of the array and Ruby &lt;em&gt;should&lt;/em&gt; scan that directory when I call &lt;code&gt;require&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;    &lt;span class='vg'&gt;$:&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;unshift&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;dirname&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='bp'&gt;__FILE__&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;..&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;lib&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Again, this works, but &lt;code&gt;$:&lt;/code&gt; dosen&amp;#8217;t feel intuitive. Some quick googling shows that &lt;code&gt;$LOAD_PATH&lt;/code&gt; is an alias for &lt;code&gt;$:&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;    &lt;span class='vg'&gt;$LOAD_PATH&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;unshift&lt;/span&gt; &lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;join&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='no'&gt;File&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;dirname&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='bp'&gt;__FILE__&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;..&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;lib&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

    &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;myclass&amp;#39;&lt;/span&gt;
    &lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;anotherclass&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now you can see immediately which file is being required. Plus, if you&amp;#8217;re writing a gem, you only need to do this &lt;em&gt;once&lt;/em&gt; in the base class and the same load path will be used in any file beneath it.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/10/23/vim-reboot-4</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/10/23/vim-reboot-4.html"/>
    <title>Vim Reboot 4</title>
    <updated>2011-10-23T00:00:00-07:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;h3 id='an_addendum'&gt;An Addendum&lt;/h3&gt;

&lt;p&gt;In a previous post I described how to get syntax highlighting working, but I forgot to add a setting to enable plugins and indentation based on filetype:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    filetype plugin indent on
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id='searching'&gt;Searching&lt;/h3&gt;

&lt;p&gt;Every vim user should know how to search for text within a file. In normal mode, hit &lt;code&gt;/&lt;/code&gt; and type in a search string. Press &lt;code&gt;Enter&lt;/code&gt; and your cursor will jump to the first occurance of that string. The following options make searching a little bit nicer:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;set &lt;/span&gt;hlsearch
    &lt;span class='nb'&gt;set &lt;/span&gt;incsearch
    &lt;span class='nb'&gt;set &lt;/span&gt;ignorecase
    &lt;span class='nb'&gt;set &lt;/span&gt;smartcase
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;hlsearch&lt;/code&gt; highlights every occurance of your search in the file after you press the &lt;code&gt;Enter&lt;/code&gt; key.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;incsearch&lt;/code&gt; moves the cursor and begins highlighting the search term as you type it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ignorecase&lt;/code&gt; will make your searching case insensitve. Searching for &amp;#8220;foobar&amp;#8221; will match &amp;#8220;foobar&amp;#8221;, &amp;#8220;FOOBAR&amp;#8221;, and everything inbetween.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;smartcase&lt;/code&gt; is used in conjunction with &lt;code&gt;ignorecase&lt;/code&gt;. If your search term contains an uppercase letter, then the search will be case sensitive. Searching for &amp;#8220;foobar&amp;#8221; will work as before, but &amp;#8220;fooBar&amp;#8221;, will only match other occurances of &amp;#8220;fooBar&amp;#8221;.&lt;/p&gt;

&lt;h3 id='status_line'&gt;Status Line&lt;/h3&gt;

&lt;p&gt;At the bottom of the vim window there is a status line that (by default) simply displays the name of currently open file. There are ways, of course, to customize this, and I&amp;#8217;ll be doing a lot more with it in a later post. For now, all I want to do is insert the cursor&amp;#8217;s current line/column number, and make sure that it is &lt;em&gt;always&lt;/em&gt; visible.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;set &lt;/span&gt;ruler
    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;laststatus&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;2
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;ruler&lt;/code&gt; displays the cursor&amp;#8217;s current line and column number.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;laststatus&lt;/code&gt; tells vim when to show it&amp;#8217;s status line. It can have 3 possible values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0&lt;/code&gt; Tells it to never appear.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;1&lt;/code&gt; Tells it to only appear when there are more than 2 windows open.&lt;/li&gt;

&lt;li&gt;&lt;code&gt;2&lt;/code&gt; Forces it to always be visible.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As I said, there are even more ways to customize this line, but for the customization I want to do, I&amp;#8217;ll need to install a plugin.&lt;/p&gt;

&lt;p&gt;This is the end of the most basic setup options. Next time I&amp;#8217;ll start enabling the plugins that I use most frequently.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/10/16/vim-reboot-3</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/10/16/vim-reboot-3.html"/>
    <title>Vim Reboot 3</title>
    <updated>2011-10-16T00:00:00-07:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;h3 id='line_numbers'&gt;Line Numbers&lt;/h3&gt;

&lt;p&gt;By default vim doesn&amp;#8217;t show line numbers. I prefer having this as it can make finding the source of exceptions slightly easier, and you waste less time by telling the person you&amp;#8217;re pairing with to go to line 12 instead of pointing at their monitor like an ape.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;set &lt;/span&gt;number
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id='whitespace'&gt;Whitespace&lt;/h3&gt;

&lt;p&gt;This section is pretty self-explanatory; it tells vim how to deal with whitespace.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;set &lt;/span&gt;nowrap

    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;tabstop&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;2
    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;shiftwidth&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;2
    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;softtabstop&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;2
    &lt;span class='nb'&gt;set &lt;/span&gt;expandtab
    &lt;span class='nb'&gt;set &lt;/span&gt;autoindent
    &lt;span class='nb'&gt;set &lt;/span&gt;smartindent
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;nowrap&lt;/code&gt; tells vim not to wrap long lines of code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tabstop&lt;/code&gt; tells vim how many columns a tab counts for. Most of the work I do is in ruby, and the standard there is 2 spaces.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;shiftwidth&lt;/code&gt; tells vim how many columns text is re-indented with when doing &amp;#171;&amp;#160;and&amp;#160;&amp;#187;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;softabstop&lt;/code&gt; controls how many columns vim uses when you hit the tab key.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;expandtab&lt;/code&gt; tells vim to use the appropriate number of spaces to insert when hitting tab.&lt;/p&gt;

&lt;p&gt;Find the last few settings a little confusing? &lt;a href='http://tedlogan.com/techblog3.html'&gt;Check out this site&lt;/a&gt; for &lt;em&gt;little&lt;/em&gt; bit better explanation. At work, we use PHP, and our standard is 4 spaces of indentation instead of 2. You can override these settings on a per file type basis by creating a &lt;em&gt;filetype&lt;/em&gt;.vim in &lt;code&gt;~/.vim/after/ftplugin&lt;/code&gt;. For example, I have a &lt;code&gt;php.vim&lt;/code&gt; file with the following:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    setlocal &lt;span class='nv'&gt;tabstop&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;4
    setlocal &lt;span class='nv'&gt;shiftwidth&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;4
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;autoindent&lt;/code&gt; simply copies the indentation of the previous line when starting a new one.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;smartindent&lt;/code&gt; automatically inserts one extra level of indentation in certain cases.&lt;/p&gt;

&lt;p&gt;There is one last thing I like to do that picked up from the &lt;a href='https://github.com/carlhuda/janus'&gt;Janus&lt;/a&gt; vim configuration: &lt;div class='highlight'&gt;
&lt;pre&gt;
&lt;code class='bash'&gt;
    &lt;span class='nb'&gt;set &lt;/span&gt;list &lt;span class='nv'&gt;listchars&lt;/span&gt;=tab:&lt;span class='se'&gt;\ \ &lt;/span&gt;,trail:&amp;middot;
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;This tells vim to put a trailing character, &lt;code&gt;&amp;middot;&lt;/code&gt; in place of any trailing whitespace. Again, this is more of a personal preference. I tend to be pretty obsseive about leaving my code and commits looking pretty.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/10/09/vim-reboot-2</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/10/09/vim-reboot-2.html"/>
    <title>Vim Reboot 2</title>
    <updated>2011-10-09T00:00:00-07:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;p&gt;In my &lt;a href='/2011/10/02/vim-reboot-1.html'&gt;last post&lt;/a&gt; I installed MacVim and setup some very basic options specifically for it. For the next few posts, I&amp;#8217;ll be focusing on features that can be applied to the more common, server-side version.&lt;/p&gt;

&lt;h3 id='syntax_highlighting'&gt;Syntax Highlighting&lt;/h3&gt;

&lt;p&gt;The first thing I wanted to have was some syntax highlighting.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;t_Co&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;256
    colorscheme mike_wombat

    syntax &lt;span class='nb'&gt;enable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;set t_Co=256&lt;/code&gt; sets vim up to run in 256 color mode (I use &lt;a href='http://www.iterm2.com/#/section/home'&gt;iTerm 2&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;colorscheme mike_wombat&lt;/code&gt; sets the colors scheme to a slightly customized version of the wombat color scheme. Like the ir_black theme from my previous post, this can be found &lt;a href='https://github.com/mcramm/dotfiles/blob/master/vim/colors/mike_wombat.vim'&gt;here&lt;/a&gt;. Just move it into &lt;code&gt;~/.vim/colors&lt;/code&gt; to use it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;syntax enable&lt;/code&gt; enables syntax highlighting.&lt;/p&gt;

&lt;h3 id='backup_directory'&gt;Backup Directory&lt;/h3&gt;

&lt;p&gt;Vim keeps a backup of any files you open in the form of &lt;em&gt;filename&lt;/em&gt;.swp. If your vim session crashes, or the connection to your server times out, then you can use this file to recover any edits you&amp;#8217;ve made.&lt;/p&gt;

&lt;p&gt;The problem is that these files can sometimes get in the way. The most common complaint I hear is with these files getting included as part of a commit to a repository.&lt;/p&gt;

&lt;p&gt;Some people choose to turn this feature off completely and not have these backups created at all. I think that these backups can be valuable and prefer to simply have them written to a different directory.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;backupdir&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;~/.vim/backup
    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;directory&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;~/.vim/backup
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Any backup files will now be created in &lt;code&gt;~/.vim/backup&lt;/code&gt;. You may need to make the directory manually before the feature will work (though you should get prompted with an error when launching vim).&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/10/02/vim-reboot-1</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/10/02/vim-reboot-1.html"/>
    <title>Vim Reboot 1</title>
    <updated>2011-10-02T00:00:00-07:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;p&gt;Over the past few years my Vim configuration has gotten out of hand. I&amp;#8217;ve tried to maintain it as best I can, but its time for a reboot. I was inspired by Avdi Grimm&amp;#8217;s recent &lt;a href='
http://avdi.org/devblog/category/emacs-reboot/'&gt;Emacs Reboot&lt;/a&gt; series and decided to do something similar for Vim.&lt;/p&gt;

&lt;p&gt;I work on a Mac, which means I prefer to use MacVim where possible. The latest snapshot for Snow Leopard can be found at &lt;a href='http://code.google.com/p/macvim/'&gt;http://code.google.com/p/macvim/&lt;/a&gt; and installing is as easy as you would expect. Simply download the snapshot, drag MacVim.app to Applications and move the mvim script to folder in your path:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;sudo mv mvim /usr/bin
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Using &lt;code&gt;mvim&lt;/code&gt; from the command line at this point should launch MacVim as you would expect.&lt;/p&gt;

&lt;p&gt;At this point, you have two options. You can continue with this series of posts on customizing your environment by hand, or you can check out &lt;a href='https://github.com/carlhuda/janus'&gt;Janus&lt;/a&gt; and get a very good default configuration. I used this initially and copied a bit of my configuration directly from it.&lt;/p&gt;

&lt;p&gt;The first thing I wanted to do was fix the (ugly) default color scheme and setup MacVim to work in full screen mode.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;.gvimrc&lt;/code&gt; file:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;touch ~/.gvimrc
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And add the following to it:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='k'&gt;if &lt;/span&gt;has&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;gui_macvim&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;)&lt;/span&gt;
    &lt;span class='s2'&gt;&amp;quot; Make fullscreen mode take up the full screen&lt;/span&gt;
&lt;span class='s2'&gt;    set fuoptions=maxhorz,maxvert&lt;/span&gt;

&lt;span class='s2'&gt;    &amp;quot;&lt;/span&gt;&lt;span class='nb'&gt;set &lt;/span&gt;the font
    &lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;guifont&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;Menlo:h10

    &lt;span class='s2'&gt;&amp;quot; Command-Return toggles full screen mode&lt;/span&gt;
&lt;span class='s2'&gt;    macmenu Window.Toggle\ Full\ Screen\ Mode key=&amp;lt;D-CR&amp;gt;&lt;/span&gt;
&lt;span class='s2'&gt;endif&lt;/span&gt;

&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt; Start with the toolbar hidden
&lt;span class='nb'&gt;set &lt;/span&gt;guioptions-&lt;span class='o'&gt;=&lt;/span&gt;T

&lt;span class='err'&gt;&amp;quot;&lt;/span&gt; Set the color scheme
&lt;span class='nb'&gt;set &lt;/span&gt;&lt;span class='nv'&gt;background&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;dark
color ir_black
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Substitute the &amp;#8220;Menlo&amp;#8221; font and &amp;#8220;ir_black&amp;#8221; color scheme with the font/scheme of your preference.&lt;/p&gt;

&lt;p&gt;Menlo should be available on your Mac if you have Snow Leopard. If you don&amp;#8217;t have it, then you should try out &lt;a href='http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/'&gt;Bitstream&lt;/a&gt;. Installation details can be found elsewhere on their website.&lt;/p&gt;

&lt;p&gt;ir_black can be found in a bunch of places, &lt;a href='https://github.com/mcramm/dotfiles/blob/master/vim/colors/ir_black.vim'&gt;the best of which is here&lt;/a&gt;. You can use this scheme by doing:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='bash'&gt;  mkdir -p ~/.vim/colors
  mv ir_black.vim ~/.vim/colors/
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Running &lt;code&gt;mvim&lt;/code&gt; from the command line should present the following:&lt;/p&gt;

&lt;p&gt;&lt;img src='https://lh6.googleusercontent.com/-ntdKpA-y-dI/ToZhZlaVFMI/AAAAAAAAAsE/8PJ663BY_1E/vim1.png' alt='Vim' /&gt;&lt;/p&gt;

&lt;p&gt;Next I&amp;#8217;ll start setting up some standard vim options and a couple of custom mappings I use quite frequently.&lt;/p&gt;</content>
  </entry>
  
  <entry>
    <id>http://mcramm.com/2011/09/30/paramater-nam</id>
    <link type="text/html" rel="alternate" href="http://mcramm.com/2011/09/30/paramater-nam.html"/>
    <title>Parameter Nam</title>
    <updated>2011-09-30T00:00:00-07:00</updated>
    <author>
      <name>Michael Cramm</name>
      <uri>http://mcramm.com/</uri>
    </author>
    <content type="html">&lt;p&gt;I recently finished a project to improve the design of the account statements our customers print off for patients. The new design was pretty heavy and I was going to need to draw a lot of variable-length text that could be aligned to the left, right or center.&lt;/p&gt;

&lt;p&gt;We use a library called &lt;a href='http://framework.zend.com/manual/en/zend.pdf.html'&gt;Zend&lt;/a&gt; to generate all of our PDFs, and it has served us well so far. The problem is that all of the previous projects used it pretty lightly and there weren&amp;#8217;t any methods written that would help with such a dynamic design. This meant I was going to have to write a lot of the code myself, (which is fine since I &lt;strong&gt;am&lt;/strong&gt; a software developer), but would probably take the project past the deadline our clients were expecting. As the day approached, we began to feel more and more pressure to ship the feature and the code suffered because of it.&lt;/p&gt;

&lt;p&gt;The following is a small excerpt from the class responsible for drawing text to the page. Note that the original project was done in php. I&amp;#8217;ve transposed it to ruby for the sake of simplicity and because I couldn&amp;#8217;t get Pygments to syntax highlight php code nicely.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;drawStaticText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;html_color&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;#000000&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;?&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;
    &lt;span class='n'&gt;getPage&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

    &lt;span class='n'&gt;setColor&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;html_color&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;setFont&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;getFont&lt;/span&gt;&lt;span class='p'&gt;(),&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;

    &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;drawText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;drawCenteredText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;html_color&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;#000000&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;?&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;

    &lt;span class='n'&gt;width&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;getTextWidth&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;getFont&lt;/span&gt;&lt;span class='p'&gt;(),&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='n'&gt;width&lt;/span&gt; &lt;span class='o'&gt;/&lt;/span&gt; &lt;span class='mi'&gt;2&lt;/span&gt;

    &lt;span class='n'&gt;drawStaticText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;html_color&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;

&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;drawRightAlignedText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;html_color&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;#000000&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;?&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;fontSize&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;

    &lt;span class='n'&gt;width&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;getTextWidth&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;getFont&lt;/span&gt;&lt;span class='p'&gt;(),&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='n'&gt;width&lt;/span&gt;

    &lt;span class='n'&gt;drawStaticText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;html_color&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;fontSize&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Yikes, look at that mess! I can see at least 3 things wrong here:&lt;/p&gt;

&lt;h3 id='1_code_duplication'&gt;1. Code Duplication&lt;/h3&gt;

&lt;p&gt;Each of these methods are overly similar. I&amp;#8217;m defaulting &lt;code&gt;fontSize&lt;/code&gt; in all three, and I&amp;#8217;m calling &lt;code&gt;getTextWidth()&lt;/code&gt; in the bottom two.&lt;/p&gt;

&lt;h3 id='2_poorly_named_methods'&gt;2. Poorly named methods&lt;/h3&gt;

&lt;p&gt;The names of these methods aren&amp;#8217;t consistent, nor do I feel the correctly convey what they&amp;#8217;re doing. The person implementing this code might not have a problem understanding what &lt;code&gt;drawCenteredText&lt;/code&gt;, does, but it would feel inconsistent next to &lt;code&gt;drawRightAlignedText&lt;/code&gt;. And why the word &amp;#8220;Static&amp;#8221; in &lt;code&gt;drawStaticText&lt;/code&gt;? What does that imply about the method?&lt;/p&gt;

&lt;h3 id='3_parameter_hell'&gt;3. Parameter Hell&lt;/h3&gt;

&lt;p&gt;There are &lt;em&gt;way&lt;/em&gt; too many parameters being passed around here. Some people regard the passing of anything more than 2 parameters to a method as a code smell, and I tend to agree. The more parameters you pass into a method makes it harder to test, looks messy, and generally create brittle code. Sometimes there is no way around it, but you should try to avoid it where possible.&lt;/p&gt;

&lt;p&gt;My focus for the remainder of this post will be in reducing the number of parameters being used. &lt;code&gt;self.page.drawText()&lt;/code&gt; is off-limits since that&amp;#8217;s the call to actual library. Everything else is fair game.&lt;/p&gt;

&lt;p&gt;I recently got Martin Fowler&amp;#8217;s &amp;#8220;Refactoring: Improving the Design of Existing Code&amp;#8221;, and it has been an amazing reference for refactorings like this. On page 295, it details the process of replacing a number of parameters sent to a method with a parameter &lt;em&gt;object&lt;/em&gt; instead:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Often you see a particular group of parameters that tend to be passed together. Several methods may use this group, either on one class or in several classes. Such a group of classes is a data clump that can be replaced with an object that carries all of this data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Moving these parameters into an object, and passing it in instead, feels like the right way to go. I should also be able to add the offset calculation required for centered/right aligned text onto the object, and remove that responsibility from the code higher up. I&amp;#8217;m still going to have a problem with building the object itself, but I should be able to initialize it with a hash and reduce the chances of it being implemented incorrectly in the future.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;TextObject&lt;/span&gt;
    &lt;span class='no'&gt;ATTRIBUTES&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;
        &lt;span class='ss'&gt;:value&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:alignment&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:color&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:font_size&lt;/span&gt;
    &lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;freeze&lt;/span&gt;

    &lt;span class='no'&gt;ATTRIBUTES&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;each&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='kp'&gt;attr&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
        &lt;span class='kp'&gt;attr_accessor&lt;/span&gt; &lt;span class='kp'&gt;attr&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;

    &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;initialize&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='kp'&gt;nil&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='no'&gt;ATTRIBUTES&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;each&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='kp'&gt;attr&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;key?&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='kp'&gt;attr&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
                &lt;span class='nb'&gt;instance_variable_set&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;@&lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='kp'&gt;attr&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='kp'&gt;attr&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
            &lt;span class='k'&gt;end&lt;/span&gt;
        &lt;span class='k'&gt;end&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;

    &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;x&lt;/span&gt;
        &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='k'&gt;unless&lt;/span&gt; &lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='ss'&gt;:right&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:center&lt;/span&gt;&lt;span class='o'&gt;].&lt;/span&gt;&lt;span class='n'&gt;include?&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;alignment&lt;/span&gt;
        &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;alignment&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='ss'&gt;:right&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;?&lt;/span&gt; &lt;span class='n'&gt;calculateOffsetForRight&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;calculateOffsetForCenter&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;

    &lt;span class='kp'&gt;private&lt;/span&gt;

    &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;calculateOffsetForRight&lt;/span&gt;
        &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='n'&gt;getWidth&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;

    &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;calculateOffsetForCenter&lt;/span&gt;
        &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt; &lt;span class='o'&gt;-&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;getWidth&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='o'&gt;/&lt;/span&gt; &lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;

    &lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;getWidth&lt;/span&gt;
        &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;value&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;size&lt;/span&gt;
        &lt;span class='c1'&gt;# In reality, this method returns pixel value for the string based on font size / family.&lt;/span&gt;
    &lt;span class='k'&gt;end&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that this object is pretty small, and while the initialization looks a little complicated, it makes using it so much easier. I can now go ahead and remove replace all of the parameters with this new object. At the same time, I&amp;#8217;ll rename &lt;code&gt;drawStaticText&lt;/code&gt; to &lt;code&gt;drawText&lt;/code&gt; to better reflect what it is doing.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;drawText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='n'&gt;text_obj&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;font_size&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;textObj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;font_size&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='mi'&gt;0&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;?&lt;/span&gt; &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;font_size&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;font_size&lt;/span&gt;
    &lt;span class='n'&gt;getPage&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='n'&gt;setColor&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;color&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;setFont&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;getFont&lt;/span&gt;&lt;span class='p'&gt;(),&lt;/span&gt; &lt;span class='n'&gt;font_size&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='nb'&gt;self&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;page&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;drawText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;value&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;y&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;UTF-8&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Finally this code is starting to shape up. This is what it would look like to use that &lt;code&gt;TextObject&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;my_text_obj&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='kp'&gt;new&lt;/span&gt; &lt;span class='no'&gt;TextObject&lt;/span&gt;&lt;span class='p'&gt;({&lt;/span&gt;
    &lt;span class='ss'&gt;:value&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Draw Me!&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:x&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='mi'&gt;12&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:y&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='mi'&gt;100&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:alignment&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='ss'&gt;:left&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:color&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;#000000&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='ss'&gt;:font_size&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='mi'&gt;12&lt;/span&gt;
&lt;span class='p'&gt;})&lt;/span&gt;

&lt;span class='n'&gt;my_text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;   &lt;span class='c1'&gt;# =&amp;gt; 12&lt;/span&gt;

&lt;span class='n'&gt;my_text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;alignment&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='ss'&gt;:right&lt;/span&gt;
&lt;span class='n'&gt;my_text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;   &lt;span class='c1'&gt;# =&amp;gt; 4&lt;/span&gt;

&lt;span class='n'&gt;my_text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;alignment&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='ss'&gt;:center&lt;/span&gt;
&lt;span class='n'&gt;my_text_obj&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;x&lt;/span&gt;   &lt;span class='c1'&gt;# =&amp;gt; 8&lt;/span&gt;

&lt;span class='n'&gt;drawText&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt; &lt;span class='n'&gt;my_text_obj&lt;/span&gt; &lt;span class='p'&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I&amp;#8217;m sure that there are other ways to refactor this code even further, but this is fine for the purposes of getting rid of all those crazy parameters. Testing the &lt;code&gt;drawText&lt;/code&gt; method now should be much easier, and I can write tests for the &lt;code&gt;TextObject&lt;/code&gt; as well.&lt;/p&gt;

&lt;p&gt;There are still other areas of this project that could use some refactoring, but thats it for at least this section. At least I can browse through this file without having to enable text-wrapping in vim.&lt;/p&gt;</content>
  </entry>
  

</feed>


