<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://nvie.com/</id>
  <title>nvie.com</title>
  <updated>2012-02-13T23:00:00Z</updated>
  <link rel="alternate" href="http://nvie.com/" />
  
  <author>
    <name>Vincent Driessen</name>
    <uri>http://nvie.com/about</uri>
  </author>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/nvie" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="nvie" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <id>tag:nvie.com,2012-02-14:/posts/vim-flake8-flake8-for-vim/</id>
    <title type="html">vim-flake8: Flake8 for Vim</title>
    <published>2012-02-13T23:00:00Z</published>
    <updated>2012-02-13T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/vim-flake8-flake8-for-vim/" />
    <content type="html">&lt;p&gt;Just a quick post to let you know that I discarded my &lt;code&gt;vim-pep8&lt;/code&gt; and
&lt;code&gt;vim-pyflakes&lt;/code&gt; Vim plugins yesterday in favor of
&lt;a href="https://github.com/nvie/vim-flake8"&gt;vim-flake8&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As you may know, PyFlakes is a static analysis tool that lets you catch static
programming errors when you write them, not when you run into them at runtime.
And &lt;code&gt;pep8&lt;/code&gt; is a Python style checking tool that enforces
&lt;a href="http://www.python.org/dev/peps/pep-0008/"&gt;PEP8&lt;/a&gt; guidelines on your code.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://pypi.python.org/pypi/flake8"&gt;Flake8&lt;/a&gt;, though, seems to be a much better
option to use these days.  It integrates both of PEP8 and PyFlakes and even
combines it with a cyclomatic complexity checker (which is irrelevant for the
Vim plugin, by the way).  To install Flake8, simply use:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ pip install flake8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After installing the plugin in Vim, you can add the following command to your
&lt;code&gt;.vimrc&lt;/code&gt; file to have it executed after every save of a Python source file.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
autocmd BufWritePost *.py call Flake8()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To avoid specific error messages from being reported, put a &lt;code&gt;# noqa&lt;/code&gt; comment
at the end of that line.&lt;/p&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;Assuming you already use &lt;a href="https://github.com/tpope/vim-pathogen"&gt;vim-pathogen&lt;/a&gt;
(which you really should), you can simply install the plugin by cloning the
&lt;a href="https://github.com/nvie/vim-flake8"&gt;repository&lt;/a&gt; into the &lt;code&gt;~/.vim/bundle&lt;/code&gt;
folder.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;Just a quick post to let you know that I discarded my &lt;code&gt;vim-pep8&lt;/code&gt; and
&lt;code&gt;vim-pyflakes&lt;/code&gt; Vim plugins yesterday in favor of
&lt;a href="https://github.com/nvie/vim-flake8"&gt;vim-flake8&lt;/a&gt;.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2012-02-02:/posts/introducing-times/</id>
    <title type="html">Introducing Times</title>
    <published>2012-02-01T23:00:00Z</published>
    <updated>2012-02-07T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/introducing-times/" />
    <content type="html">&lt;p&gt;Lately I&amp;#x2019;ve been getting sick of working with datetimes and timezones in
Python.  The standard library offers many different conversion routines, but
does not prescribe a best practice way to deal with them.  Luckily, Armin
Ronacher did in his article &lt;a href="http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/"&gt;Dealing with Timezones in
Python&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The summary is to never ever work with local datetimes.  When a local datetime
is input, immediately convert it to universal time and only ever store or
calculate with those.  Only when &lt;em&gt;presenting&lt;/em&gt; datetimes to the end user,
convert them to local time again.&lt;/p&gt;
&lt;p&gt;This seems simple enough, alright.  But to actually &lt;em&gt;do&lt;/em&gt; it in Python, you
still have to think about how to implement it correctly.  Every. Single. Time.
&lt;code&gt;pytz&lt;/code&gt; does help a bit here, but it still isn&amp;#x2019;t trivial.  It should be.&lt;/p&gt;
&lt;p&gt;Meet &lt;a href="https://github.com/nvie/times"&gt;&lt;code&gt;Times&lt;/code&gt;&lt;/a&gt;, a very small Python library to
deal with conversions from universal to local timezones and vice versa.  It&amp;#x2019;s
focused on simplicity and opinionated about what is good practice.&lt;/p&gt;
&lt;h3&gt;Example use&lt;/h3&gt;
&lt;p&gt;Imagine you&amp;#x2019;re building a web app that allows your users to set an alarm.  Say
that someone in the Netherlands sets an alarm to 9:30 am.  You can use &lt;code&gt;times&lt;/code&gt;
to simplify this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-pycon"&gt;
&amp;gt;&amp;gt;&amp;gt; import times
&amp;gt;&amp;gt;&amp;gt; import datetime
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; local_time = datetime.datetime(2012, 2, 3, 9, 30, 0)
&amp;gt;&amp;gt;&amp;gt; universal_time = times.to_universal(local_time, 'Europe/Amsterdam')
&amp;gt;&amp;gt;&amp;gt; universal_time
datetime.datetime(2012, 2, 3, 8, 30)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, this &lt;code&gt;universal_time&lt;/code&gt; variable is safe to store or calculate with.&lt;/p&gt;
&lt;p&gt;Once you want to show this date to the user again, simply format it for the
given timezone:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-pycon"&gt;
&amp;gt;&amp;gt;&amp;gt; times.format(universal_time, 'Europe/Amsterdam') 
'2012-02-03 09:30:00+0100'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If your app allows users to share alerts, it is just as easy to present the
alert date to an end user in New Zealand as well:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-pycon"&gt;
&amp;gt;&amp;gt;&amp;gt; times.format(universal_time, 'Pacific/Auckland') 
'2012-02-03 21:30:00+1300'
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Current time&lt;/h3&gt;
&lt;p&gt;If you ever need to record the current time, you can use&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-pycon"&gt;
&amp;gt;&amp;gt;&amp;gt; times.now()
datetime.datetime(2012, 2, 2, 16, 4, 40, 283090)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which is actually just an alias to &lt;code&gt;datetime.datetime.utcnow()&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;&lt;ins&gt;Converting from other sources&lt;/ins&gt;&lt;/h3&gt;
&lt;p&gt;&lt;ins&gt;I&amp;#x2019;ve added the ability to create universal times from two other sources: &lt;span class="caps"&gt;UNIX&lt;/span&gt;
timestamps and date strings.  To use any of these, simply pass them to the
&lt;code&gt;to_universal&lt;/code&gt; function, like so:&lt;/ins&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-pycon"&gt;
&amp;gt;&amp;gt;&amp;gt; time.time()
1328729274.982
&amp;gt;&amp;gt;&amp;gt; times.to_universal(1328729274.982)
datetime.datetime(2012, 2, 8, 19, 27, 54, 982000)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;ins&gt;Note that &lt;span class="caps"&gt;UNIX&lt;/span&gt; timestamps &lt;em&gt;must&lt;/em&gt; be in &lt;span class="caps"&gt;UTC&lt;/span&gt; (which the output of &lt;code&gt;time.time()&lt;/code&gt;
is).  Local &lt;span class="caps"&gt;UNIX&lt;/span&gt; timestamps are not accepted.&lt;/ins&gt;&lt;/p&gt;
&lt;p&gt;&lt;ins&gt;To create universal times from string representations, &lt;code&gt;Times&lt;/code&gt; uses the
advanced parser from the &lt;code&gt;python-dateutil&lt;/code&gt; library.  Time zones are
automatically recognized if such info is encoded in the string representation.
In any other case, you are required to provide it explicitly.  Two examples to
illustrate both variants:&lt;/ins&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-pycon"&gt;
&amp;gt;&amp;gt;&amp;gt; # Timezone-aware date formats don't require a source timezone
&amp;gt;&amp;gt;&amp;gt; date_str = '2012-02-08 19:27:54+0100'
&amp;gt;&amp;gt;&amp;gt; times.to_universal(date_str)
datetime.datetime(2012, 2, 8, 18, 27, 54)

&amp;gt;&amp;gt;&amp;gt; # Timezone-less date formats require an explicit source timezone
&amp;gt;&amp;gt;&amp;gt; date_str = '2012-02-08 19:27:54'
&amp;gt;&amp;gt;&amp;gt; times.to_universal(date_str, 'Asia/Singapore')
datetime.datetime(2012, 2, 8, 11, 27, 54)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Installing&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Times&lt;/code&gt; is on PyPI (&lt;a href="http://pypi.python.org/pypi/times"&gt;link&lt;/a&gt;), so just &lt;code&gt;pip
install times&lt;/code&gt; to use it.&lt;/p&gt;
&lt;p&gt;Of course, you can &lt;a href="http://github.com/nvie/times"&gt;fork me on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As usual, &lt;code&gt;Times&lt;/code&gt; is licensed under the liberal terms of the &lt;span class="caps"&gt;BSD&lt;/span&gt; license.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;Lately I&amp;#8217;ve been getting sick of working with datetimes and timezones in
Python.  The standard library offers many different conversion routines, but
does not prescribe a best practice way to deal with them.  Luckily, Armin
Ronacher did in his article &lt;a href="http://lucumr.pocoo.org/2011/7/15/eppur-si-muove/"&gt;Dealing with Timezones in
Python&lt;/a&gt;.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2011-10-06:/posts/thanks-steve/</id>
    <title type="html">Thank you, Steve</title>
    <published>2011-10-05T22:00:00Z</published>
    <updated>2011-10-05T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/thanks-steve/" />
    <content type="html">&lt;p&gt;This night, I woke up to the news that
&lt;a href="http://www.apple.com/stevejobs/"&gt;Steve Jobs passed away&lt;/a&gt;.  I did not expect to
be this touched by the news, although it was to be expected.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2011/10/steve.jpg" class="center shadow" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Steve Jobs has revolutionized the industry several times, each time showing
customers what is possible, &lt;em&gt;before&lt;/em&gt; customers could even dream about it.&lt;/p&gt;
&lt;p&gt;He sold personal computers to households, applied the graphical user interface
and the mouse to those, and then, in 2007, he saw a future for touch
interfaces that fit in your pockets.  Not only did he &lt;em&gt;dream&lt;/em&gt;, he was able to
actually &lt;em&gt;build&lt;/em&gt; them.  Each of these have set the standard in the industry.
It is incredible how a single man was able to sketch this vision, inspire
people to move mountains, and to reach these goals with Apple.&lt;/p&gt;
&lt;h2&gt;Reshaping the world&lt;/h2&gt;
&lt;p&gt;It is illustrative that the news of Steve&amp;#x2019;s death had not even made it to our
news paper this morning, but was read by millions of people on their iPhones
instead.&lt;/p&gt;
&lt;p&gt;Obama used beautiful words to express his impact on mankind:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#x201C;Brave enough to think differently, bold enough to believe he
could change the world, and talented enough to do it.&amp;#x201D;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Any person that ever touched an Apple device knows it breathes the dedication
and craftsmanship that has been put into them, and it is an awesome feeling.
Our kids will take this for granted, but we are still aware of where we came
from.&lt;/p&gt;
&lt;h2&gt;Impact on developers&lt;/h2&gt;
&lt;p&gt;But Steve has also been able to make developers around the world more aware of
their impact to users.  That you should push hard to leave out unnecessary
details.  That it is important to pay attention to detail.  That &lt;em&gt;building&lt;/em&gt;
software might be hard, but &lt;em&gt;using&lt;/em&gt; software shouldn&amp;#x2019;t.&lt;/p&gt;
&lt;p&gt;It is his heritage that every creative person on earth will feel Steve looking
over his shoulder to push him just a little bit further at each detail.  It
will result in better products everywhere.&lt;/p&gt;
&lt;p&gt;The ripple Steve caused in our industry will at least ripple on for a few
decades throughout new products and technologies and will be the basis for how
our children communicate, are educated, and perceive life.&lt;/p&gt;
&lt;p&gt;What changed today is that we need to figure it out by ourselves, without his
vision.  That is scary, but we might just be old enough now ;)&lt;/p&gt;
&lt;p&gt;Thanks for teaching us.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;This night, I woke up to the news that
&lt;a href="http://www.apple.com/stevejobs/"&gt;Steve Jobs passed away&lt;/a&gt;.  I did not expect to
be this touched by the news, although it was to be expected.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2011-10-05:/posts/chords-lyrics/</id>
    <title type="html">Chords + Lyrics</title>
    <published>2011-10-04T22:00:00Z</published>
    <updated>2011-10-21T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/chords-lyrics/" />
    <content type="html">&lt;p&gt;It&amp;#x2019;s been quite a while since I took the time to update this blog.  Many
things have happened in the meanwhile, though.  The most important happening
for me is that I launched an iPad app and I founded a company called
&lt;a href="http://www.3rdcloud.com"&gt;3rd Cloud&lt;/a&gt; last week.&lt;/p&gt;
&lt;h2&gt;Hello, Chords + Lyrics!&lt;/h2&gt;
&lt;p&gt;An annoying problem amateur musicians might be familiar with is that chords or
tablature websites all look very differently, format their song data in
various formats, and oftentimes are just plain ugly.  Oh, and they&amp;#x2019;re
generally paved with ads, too.  So to scratch our own itches, I teamed up with
&lt;a href="http://twitter.com/jr00n"&gt;@jr00n&lt;/a&gt; from &lt;a href="http://www.studiowolff.nl"&gt;StudioWolff&lt;/a&gt;
to create &lt;a href="http://www.chordsandlyricsapp.com"&gt;Chords + Lyrics&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Chords + Lyrics is a simple music manager for your iPad that allows you to
easily import songs and lyrics from your favorite chords website (that means:
&lt;em&gt;any&lt;/em&gt; website&amp;#x2014;it recognizes the chords semantically):&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2011/10/showcase3.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Once imported, the chords become editable objects in the form of bubbles,
which makes it easy for you to edit or finetune the imported songs.
A carefully selected choice of fonts is used to create a readable and uniform
look and feel for your song&amp;#x2019;s chords and lyrics:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2011/10/showcase1.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Furthermore, once the editing is done, you can simply take Chords + Lyrics on
stage with your band or solo performance and leave your stack of sheet music
at home.  When the device is rotated into landscape orientation, the user
interface transforms into a big music stand that arranges the songs of choice
as a stack of virtual music sheets in the order of your playlist:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2011/10/showcase4.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;You can get a sneak peak of the app by watching this video:&lt;/p&gt;
&lt;p&gt;&lt;iframe width="560" height="420" src="http://www.youtube.com/embed/pG51bemU0ok?rel=0&amp;amp;hd=1" frameborder="0"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;p&gt;The app is sold at $5.99.  Check us out in the
&lt;a href="http://itunes.apple.com/us/app/chords-lyrics/id462295346?ls=1&amp;amp;mt=8"&gt;App Store&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://itunes.apple.com/us/app/chords-lyrics/id462295346?ls=1&amp;amp;mt=8"&gt;&lt;img src="http://nvie.com/img/2011/10/appstore_badge.png" class="center" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;The Role of Appsterdam&lt;/h2&gt;
&lt;p&gt;Jeroen and I met during &lt;a href="http://www.iosdevcamp.org/"&gt;iOS Dev Camp&lt;/a&gt; last March
and immediately were excited with the idea for Chords + Lyrics.  We even
received the &lt;em&gt;Most Likely to Succeed&lt;/em&gt; award from
&lt;a href="http://twitter.com/dom"&gt;Dom Sogolla&lt;/a&gt; and &lt;a href="http://twitter.com/bmf"&gt;Mike Lee&lt;/a&gt; at
the end of those two days, which got us even more excited about the project.&lt;/p&gt;
&lt;p&gt;We started hacking away at it in our spare time for the next few months.
While at the same time, by some kind of lucky coincidence, the same Mike Lee
started building an awesome developer community for app developers:
&lt;a href="http://www.appsterdam.rs"&gt;Appsterdam&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2011/10/appsterdam.png" class="center shadow" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Many of our thanks therefore go out to all of the Appsterdammers, in
particular Mike and &lt;a href="http://twitter.com/judykitteh"&gt;Judy&lt;/a&gt;, for inspiring us at
the moments we got stuck and for the helpful pieces of advice we got from
them.  Without the Appsterdam community, the project may have never seen the
light of day, or be much less awesome.&lt;/p&gt;
&lt;p&gt;Let this be the first of many apps!&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;It&amp;#8217;s been quite a while since I took the time to update this blog.  Many
things have happened in the meanwhile, though.  The most important happening
for me is that I launched an iPad app and I founded a company called
&lt;a href="http://www.3rdcloud.com"&gt;3rd Cloud&lt;/a&gt; last week.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2011-01-27:/posts/a-git-flow-screencast/</id>
    <title type="html">A git-flow screencast</title>
    <published>2011-01-26T23:00:00Z</published>
    <updated>2011-05-24T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/a-git-flow-screencast/" />
    <content type="html">&lt;p&gt;Mr. &lt;a href="http://www.davebock.com/"&gt;Dave Bock&lt;/a&gt; of Code Sherpa&amp;#x2019;s put together a nice
screencast demonstrating a few of the most important git-flow features on
their &lt;a href="http://www.codesherpas.com/portfolio/publications"&gt;publications&lt;/a&gt; page.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://codesherpas.com/screencasts/on_the_path_gitflow.mov"&gt;&lt;img src="http://nvie.com/img/2011/01/screencast_still.png" class="center" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Many thanks to Dave for creating this!&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;Dave Bock created a nice video on using git-flow.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-11-16:/posts/python-vs-ruby-survey/</id>
    <title type="html">Survey: Python vs Ruby Test Ecosystems</title>
    <published>2010-11-15T23:00:00Z</published>
    <updated>2010-11-15T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/python-vs-ruby-survey/" />
    <content type="html">&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; Please help out and take &lt;a href="http://goo.gl/j0blw"&gt;the survey&lt;/a&gt;.  It
only takes one or two minutes.&lt;/p&gt;
&lt;p&gt;In my spare time, I love to read up on many different topics that are
happening in the modern world of software development.  On many occasions, the
initiatives that I find most interesting are happening in the Python and Ruby
communities.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/11/py-vs-ruby.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;I immediately have to admit that I&amp;#x2019;m not too actively involved in the Ruby
community yet.  It is a language that I don&amp;#x2019;t have much &amp;#x201C;handson experience&amp;#x201D;
with.  Although I think the Ruby community is a bit more chaotic than
Python&amp;#x2019;s, I also believe that more exciting things are happening there.  Ruby
definitely got the more snazzy and sexier appeal of the two, but I also think
it&amp;#x2019;s the more naive brother of the two that gets in trouble in its teen years
(think drugs and jail).&lt;/p&gt;
&lt;h2&gt;Lovable and Loathsome Language Features&lt;/h2&gt;
&lt;p&gt;I have always found it really hard to express what I dislike about Ruby.  In
my college years, I really enjoyed functional programming and I absolutely
adore the influences Ruby got from that world.  Solving programming problems
with the typical Ruby language constructs like blocks is very satisfying and
feels really elegant.  Next to that, Ruby makes a gorgeous language for
creating DSLs.&lt;/p&gt;
&lt;p&gt;Yet, the &amp;#x201C;black magic&amp;#x201D; and the implicit behaviour that also accompany Ruby
give me the eerie feeling that I&amp;#x2019;m not in control.&lt;/p&gt;
&lt;p&gt;When I stumbled upon this video by Gary Bernhardt: &lt;a href="http://vimeo.com/9471538"&gt;Python vs Ruby: A Battle
to The Death&lt;/a&gt;, all the pieces of the puzzle fell
together for me.  In this talk, Gary puts to words what my feelings about the
two languages are to a great extent.  Result: I love both and I hate both.&lt;/p&gt;
&lt;h2&gt;Uncovering Test Ecosystems&lt;/h2&gt;
&lt;p&gt;Especially the conclusions Gary draws about RSpec being a superiour
specification language is something I share.  There simply is no good
equivalent of RSpec for Python.  In fact, it&amp;#x2019;s impossible to ever create one
in Python, due to Python&amp;#x2019;s inability to inject methods into &lt;code&gt;object&lt;/code&gt; and its
lack of blocks, and therefore, its lack of &lt;span class="caps"&gt;DSL&lt;/span&gt; capabilities.  (Oh yes, there
&lt;a href="http://darcs.idyll.org/~t/projects/pinocchio/doc/#spec-generate-test-description-from-test-class-method-names"&gt;have&lt;/a&gt;
&lt;a href="http://bitbucket.org/garybernhardt/mote/"&gt;been&lt;/a&gt;
&lt;a href="https://gist.github.com/327596"&gt;attempts&lt;/a&gt;.  None of them are as good as the
real thing.)&lt;/p&gt;
&lt;p&gt;This made me think.  Does Ruby have a more mature testing culture?  If
I browse around interesting projects on Github, for example, I always get the
feeling that the Ruby projects have better tests and better coverage than the
Python ones (sorry, no scientific proof here).
&lt;span class="small lite"&gt;&amp;lt;bait&amp;gt;Maybe they have to &lt;em&gt;because&lt;/em&gt; of the magic in Ruby?
;)&amp;lt;/bait&amp;gt;&lt;/span&gt;  But most importantly, the Ruby culture seem to &lt;em&gt;care more&lt;/em&gt;
(or at least have higher awareness) about actually testing their code at all.&lt;/p&gt;
&lt;p&gt;At the same time, I get the feeling that the Ruby culture has &lt;em&gt;less&lt;/em&gt; testing
tools available.  Maybe this is because I simply don&amp;#x2019;t know the Ruby community
as well as I know Python&amp;#x2019;s, but maybe there has been a lot more consensus and
standardisation already.&lt;/p&gt;
&lt;h2&gt;Only one way to find out&lt;/h2&gt;
&lt;p&gt;This made me curious, so I decided to pull up a &lt;a href="http://goo.gl/j0blw"&gt;quick
survey&lt;/a&gt;.  I hereby invite all Python and Ruby
developers out there to participate in it.  Please help spread the word on
Twitter to get as many participants as possible.  The more answers received,
the stronger the map of available and popular tools will be.  I&amp;#x2019;ve also
included a few questions on the use of continuous build and integration
systems.  After taking the survey you can see the results so far.&lt;/p&gt;
&lt;p&gt;I&amp;#x2019;ll make sure to blog about any interesting conclusions that can be drawn
from the numbers that I will gather with this.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;In this post I call out for participation in &lt;a href="http://goo.gl/j0blw"&gt;a
survey&lt;/a&gt; that I quickly put together this evening
to get a better overview of the most-used unit testing, spec and code
coverage tools for both Python and Ruby.&lt;/p&gt;
&lt;p&gt;Suffice to say that I will blog about any interesting results or
conclusions that I will draw from this survey.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-09-14:/posts/how-i-boosted-my-vim/</id>
    <title type="html">How I boosted my Vim</title>
    <published>2010-09-13T22:00:00Z</published>
    <updated>2010-09-22T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/how-i-boosted-my-vim/" />
    <content type="html">&lt;p&gt;A few weeks ago, I felt inspired by articles from &lt;a href="http://jeffkreeftmeijer.com/2010/stumbling-into-vim/"&gt;Jeff
Kreeftmeijer&lt;/a&gt; and &lt;a href="http://lucumr.pocoo.org/2010/7/29/sharing-vim-tricks"&gt;Armin
Ronacher&lt;/a&gt;.  I took some
time to configure and fine-tune my Vim environment.  A lot of new stuff made it
into my &lt;code&gt;.vimrc&lt;/code&gt; file and my &lt;code&gt;.vim&lt;/code&gt; directory.  This blog post is a summary
describing what I&amp;#x2019;ve added and how I use it in my daily work.&lt;/p&gt;
&lt;p&gt;Before doing anything else, make sure you have the following line in your
&lt;code&gt;.vimrc&lt;/code&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" This must be first, because it changes other options as side effect
set nocompatible
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="pathogen"&gt;Step 0: make the customization process easier&lt;/h2&gt;
&lt;p&gt;Before starting configuring, it&amp;#x2019;s useful to install
&lt;a href="http://www.vim.org/scripts/script.php?script_id=2332"&gt;pathogen&lt;/a&gt;.  Plugins in
Vim are files that you drop in subdirectories of your &lt;code&gt;.vim/&lt;/code&gt; directory.  Many
plugins exist of only a single file that should be dropped in &lt;code&gt;.vim/plugin&lt;/code&gt;,
but some exist of multiple files.  For example, they come with documentation,
or ship syntax files.  In those cases, files need to be dropped into
&lt;code&gt;.vim/doc&lt;/code&gt; and &lt;code&gt;.vim/syntax&lt;/code&gt;.  This makes it difficult to remove the plugin
afterwards.  After installing pathogen, you can simply unzip a plugin
distribution into &lt;code&gt;.vim/bundle/myplugin&lt;/code&gt;, under which the required
subdirectories are created.  Removing the plugin, then, is as simple as
removing the &lt;code&gt;myplugin&lt;/code&gt; directory.&lt;/p&gt;
&lt;p&gt;So, download &lt;code&gt;pathogen.vim&lt;/code&gt;, move it into the &lt;code&gt;.vim/autoload&lt;/code&gt; directory (create
it if necessary) and add the following lines to your &lt;code&gt;.vimrc&lt;/code&gt;, to activate it:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" Use pathogen to easily modify the runtime path to include all
" plugins under the ~/.vim/bundle directory
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next, I&amp;#x2019;ve remapped the leader key to &lt;code&gt;,&lt;/code&gt; (comma) instead of the default &lt;code&gt;\&lt;/code&gt;
(backslash), just because I like it better.  Since in Vim&amp;#x2019;s default
configuration, almost every key is already mapped to a command, there needs to
be some sort of standard &amp;#x201C;free&amp;#x201D; key where you can place custom mappings under.
This is called the &amp;#x201C;mapleader&amp;#x201D;, and can be defined like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" change the mapleader from \ to ,
let mapleader=","
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once that is done, this is a little tweak that is a time-saver while you&amp;#x2019;re
building up your &lt;code&gt;.vimrc&lt;/code&gt;.  Here, we start using the leader key:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" Quickly edit/reload the vimrc file
nmap &amp;lt;silent&amp;gt; &amp;lt;leader&amp;gt;ev :e $MYVIMRC&amp;lt;CR&amp;gt;
nmap &amp;lt;silent&amp;gt; &amp;lt;leader&amp;gt;sv :so $MYVIMRC&amp;lt;CR&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This effectively maps the &lt;code&gt;,ev&lt;/code&gt; and &lt;code&gt;,sv&lt;/code&gt; keys to edit/reload &lt;code&gt;.vimrc&lt;/code&gt;.  (I got
this from &lt;a href="http://derekwyatt.org/"&gt;Derek Wyatt&lt;/a&gt;&amp;#x2019;s &lt;code&gt;.vimrc&lt;/code&gt; file.)&lt;/p&gt;
&lt;h2&gt;Change Vim behaviour&lt;/h2&gt;
&lt;p&gt;One particularly useful setting is &lt;code&gt;hidden&lt;/code&gt;.  Its name isn&amp;#x2019;t too descriptive,
though.  It &lt;em&gt;hides&lt;/em&gt; buffers instead of &lt;em&gt;closing&lt;/em&gt; them.  This means that you can
have unwritten changes to a file and open a new file using &lt;code&gt;:e&lt;/code&gt;, without being
forced to write or undo your changes first.  Also, undo buffers and marks are
preserved while the buffer is open.  This is an absolute must-have.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set hidden
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are some of the most basic settings that you probably want to enable,
too:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set nowrap        " don't wrap lines
set tabstop=4     " a tab is four spaces
set backspace=indent,eol,start
                  " allow backspacing over everything in insert mode
set autoindent    " always set autoindenting on
set copyindent    " copy the previous indentation on autoindenting
set number        " always show line numbers
set shiftwidth=4  " number of spaces to use for autoindenting
set shiftround    " use multiple of shiftwidth when indenting with '&amp;lt;' and '&amp;gt;'
set showmatch     " set show matching parenthesis
set ignorecase    " ignore case when searching
set smartcase     " ignore case if search pattern is all lowercase,
                  "    case-sensitive otherwise
set smarttab      " insert tabs on the start of a line according to
                  "    shiftwidth, not tabstop
set hlsearch      " highlight search terms
set incsearch     " show search matches as you type
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is a lot more goodness in my
&lt;a href="http://github.com/nvie/vimrc/raw/master/vimrc"&gt;&lt;code&gt;.vimrc&lt;/code&gt;&lt;/a&gt; file, which is put in
there with a lot of love.  I&amp;#x2019;ve commented most of it, too.  Feel free to poke
around in it.&lt;/p&gt;
&lt;p&gt;Also, I like Vim to have a large undo buffer, a large history of commands,
ignore some file extensions when completing names by pressing Tab, and be
silent about invalid cursor moves and other errors.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set history=1000         " remember more commands and search history
set undolevels=1000      " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title                " change the terminal's title
set visualbell           " don't beep
set noerrorbells         " don't beep
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Oh, and man&amp;#x2026; never ever let Vim write a backup file!  They did that in the
70&amp;#x2019;s.  Use &lt;a href="http://git-scm.com/"&gt;modern&lt;/a&gt; ways for tracking your changes, for
God&amp;#x2019;s sake.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set nobackup
set noswapfile
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;ins&gt;There have been some passionate responses about this in comments, so a warning
may be appropriate here.  If you care about recovering after a Vim or terminal
emulator crash, or you often load huge files into memory, do &lt;strong&gt;not&lt;/strong&gt; disable the
swapfile.  I personally save/commit so
&lt;a href="http://jeffkreeftmeijer.com/2010/git-your-act-together/#commit-all-the-fucking-time"&gt;often&lt;/a&gt;
that the swap file adds nothing.  Sometimes I conciously kill a terminal
forcefully, and I only find the swap file recovery process annoying.&lt;/ins&gt;&lt;/p&gt;
&lt;h2&gt;Use file type plugins&lt;/h2&gt;
&lt;p&gt;Vim can detect file types (by their extension, or by peeking inside the file).
This enabled Vim to load plugins, settings or key mappings that are only useful
in the context of specific file types.  For example, a Python syntax checker
plugin only makes sense in a Python file.  Finally, indenting intelligence is
enabled based on the syntax rules for the file type.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
filetype plugin indent on
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To set some file type specific settings, you can now use the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
autocmd filetype python set expandtab
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To remain compatible with older versions of Vim that do not have the &lt;code&gt;autocmd&lt;/code&gt;
functions, always wrap those functions inside a block like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
if has('autocmd')
    ...
endif
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Enable syntax highlighting&lt;/h2&gt;
&lt;p&gt;Somewhat related to the file type plugins is the syntax highlighting of
different types of source files.  Vim uses syntax definitions to highlight
source code.  Syntax definitions simply declare where a function name starts,
which pieces are commented out and what are keywords.  To color them, Vim uses
colorschemes.  You can load custom color schemes by placing them in
&lt;code&gt;.vim/colors&lt;/code&gt;, then load them using the &lt;code&gt;colorscheme&lt;/code&gt; command.  You have to try
what you like most.  I like
&lt;a href="http://hcalves.deviantart.com/art/Mustang-Vim-Colorscheme-98974484"&gt;mustang&lt;/a&gt; a
lot.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
if &amp;amp;t_Co &amp;gt;= 256 || has("gui_running")
   colorscheme mustang
endif

if &amp;amp;t_Co &amp;gt; 2 || has("gui_running")
   " switch syntax highlighting on, when the terminal has colors
   syntax on
endif
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this case, mustang is only loaded if the terminal emulator Vim runs in
supports at least 256 colors (or if you use the &lt;span class="caps"&gt;GUI&lt;/span&gt; version of Vim).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;: if you&amp;#x2019;re using a terminal emulator that can show 256 colors, try
setting &lt;code&gt;TERM=xterm-256color&lt;/code&gt; in your terminal configuration or in your shell&amp;#x2019;s
.rc file.&lt;/p&gt;
&lt;h2&gt;Change editing behaviour&lt;/h2&gt;
&lt;p&gt;When you write a lot of code, you probably want to obey certain style rules.
In some programming languages (like Python), whitespace is important, so you
may not just swap tabs for spaces and even the number of spaces is important.&lt;/p&gt;
&lt;p&gt;Vim can highlight whitespaces for you in a convenient way:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set list
set listchars=tab:&amp;gt;.,trail:.,extends:#,nbsp:.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This line will make Vim set out tab characters, trailing whitespace and
invisible spaces visually, and additionally use the &lt;code&gt;#&lt;/code&gt; sign at the end of
lines to mark lines that extend off-screen.  For more info, see &lt;code&gt;:h listchars&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In some files, like &lt;span class="caps"&gt;HTML&lt;/span&gt; and &lt;span class="caps"&gt;XML&lt;/span&gt; files, tabs are fine and showing them is
really annoying, you can disable them easily using an &lt;code&gt;autocmd&lt;/code&gt; declaration:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
autocmd filetype html,xml set listchars-=tab:&amp;gt;.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One caveat when setting &lt;code&gt;listchars&lt;/code&gt;: if nothing happens, you have probably not
enabled &lt;code&gt;list&lt;/code&gt;, so try &lt;code&gt;:set list&lt;/code&gt;, too.&lt;/p&gt;
&lt;h3&gt;Pasting large amounts of text into Vim&lt;/h3&gt;
&lt;p&gt;Every Vim user likes to enable auto-indenting of source code, so Vim can
intelligently position you cursor on the next line as you type.  This has one
big ugly consequence however: when you paste text into your terminal-based Vim
with a right mouse click, Vim cannot know it is coming from a paste.  To Vim,
it looks like text entered by someone who can type incredibly fast :)  Since
Vim thinks this is regular key strokes, it applies all auto-indenting and
auto-expansion of defined abbreviations to the input, resulting in often
cascading indents of paragraphs.&lt;/p&gt;
&lt;p&gt;There is an easy option to prevent this, however.  You can temporarily switch
to &amp;#x201C;paste mode&amp;#x201D;, simply by setting the following option:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set pastetoggle=&amp;lt;F2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, when in insert mode, ready to paste, if you press &lt;code&gt;&amp;lt;F2&amp;gt;&lt;/code&gt;, Vim will switch
to paste mode, disabling all kinds of smartness and just pasting a whole buffer
of text.  Then, you can disable paste mode again with another press of &lt;code&gt;&amp;lt;F2&amp;gt;&lt;/code&gt;.
Nice and simple.  Compare paste mode disabled vs enabled:&lt;/p&gt;
&lt;p class="autoalign"&gt;&lt;img src="http://nvie.com/img/2010/08/ugly-paste.png" alt=""&gt;
&lt;img src="http://nvie.com/img/2010/08/better-paste.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;ins&gt;Another great trick I read in a &lt;a href="http://www.reddit.com/r/programming/comments/ddbuc/how_i_boosted_my_vim/c0zelsm"&gt;reddit
comment&lt;/a&gt;
is to use &lt;code&gt;&amp;lt;C-r&amp;gt;+&lt;/code&gt; to paste right from the OS paste board.  Of course, this
only works when running Vim locally (i.e. not over an &lt;span class="caps"&gt;SSH&lt;/span&gt; connection).&lt;/ins&gt;&lt;/p&gt;
&lt;h3&gt;Enable the mouse&lt;/h3&gt;
&lt;p&gt;While using the mouse is considered a deadly sin among Vim users, there &lt;em&gt;are&lt;/em&gt; a
few features about the mouse that can really come to your advantage.  Most
notably&amp;#x2014;scrolling.  In fact, it&amp;#x2019;s the only thing I use it for.&lt;/p&gt;
&lt;p&gt;Also, if you are a rookie Vim user, setting this value will make your Vim
experience definitively feel more natural.&lt;/p&gt;
&lt;p&gt;To enable the mouse, use:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
set mouse=a
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, this comes at one big disadvantage: when you run Vim inside a
terminal, the terminal itself cannot control your mouse anymore.  Therefore,
you cannot select text anymore with the terminal (to copy it to the system
clipboard, for example).&lt;/p&gt;
&lt;p&gt;To be able to have the best of both worlds, I wrote this simple Vim plugin:
&lt;a href="http://github.com/nvie/vim-togglemouse"&gt;vim-togglemouse&lt;/a&gt;.  It maps &lt;code&gt;&amp;lt;F12&amp;gt;&lt;/code&gt; to
toggle your mouse &amp;#x201C;focus&amp;#x201D; between Vim and the terminal.&lt;/p&gt;
&lt;p&gt;Small plugins like these are really useful, yet have the additional benefit of
lowering the barrier of learning the Vim scripting language.  At the core, this
plugin exists of only one simple function:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
fun! s:ToggleMouse()
    if !exists("s:old_mouse")
        let s:old_mouse = "a"
    endif

    if &amp;amp;mouse == ""
        let &amp;amp;mouse = s:old_mouse
        echo "Mouse is for Vim (" . &amp;amp;mouse . ")"
    else
        let s:old_mouse = &amp;amp;mouse
        let &amp;amp;mouse=""
        echo "Mouse is for terminal"
    endif
endfunction
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Get efficient: shortcut mappings&lt;/h3&gt;
&lt;p&gt;The following trick is a really small one, but a super-efficient one, since it
strips off two full keystrokes from almost every Vim command:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
nnoremap ; :
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For example, to save a file, you type &lt;code&gt;:w&lt;/code&gt; normally, which means:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Press and hold Shift&lt;/li&gt;
	&lt;li&gt;Press &lt;code&gt;;&lt;/code&gt;
&lt;/li&gt;
	&lt;li&gt;Release the Shift key&lt;/li&gt;
	&lt;li&gt;Press &lt;code&gt;w&lt;/code&gt;
&lt;/li&gt;
	&lt;li&gt;Press Return&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This trick strips off steps 1 and 3 for &lt;strong&gt;each&lt;/strong&gt; Vim command.  It takes some
times for your muscle memory to get used to this new &lt;code&gt;;w&lt;/code&gt; command, but once you
use it, you don&amp;#x2019;t want to go back!&lt;/p&gt;
&lt;p&gt;I also find this key binding very useful, since I like to reformat paragraph
text often.  Just set your cursor inside a paragraph and press &lt;code&gt;Q&lt;/code&gt; (or select a
visual block and press &lt;code&gt;Q&lt;/code&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" Use Q for formatting the current paragraph (or selection)
vmap Q gq
nmap Q gqap
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are still getting used to Vim and want to force yourself to stop using
the arrow keys, add this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
map &amp;lt;up&amp;gt; &amp;lt;nop&amp;gt;
map &amp;lt;down&amp;gt; &amp;lt;nop&amp;gt;
map &amp;lt;left&amp;gt; &amp;lt;nop&amp;gt;
map &amp;lt;right&amp;gt; &amp;lt;nop&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you like long lines with line wrapping enabled, this solves the problem that
pressing down jumpes your cursor &amp;#x201C;over&amp;#x201D; the current line to the next line.  It
changes behaviour so that it jumps to the next row in the editor (much more
natural):&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
nnoremap j gj
nnoremap k gk
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When you start to use Vim more professionally, you want to work with multiple
windows open.  Navigating requires you to press &lt;code&gt;C-w&lt;/code&gt; first, then a navigation
command (h, j, k, l).  This makes it easier to navigate focus through windows:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" Easy window navigation
map &amp;lt;C-h&amp;gt; &amp;lt;C-w&amp;gt;h
map &amp;lt;C-j&amp;gt; &amp;lt;C-w&amp;gt;j
map &amp;lt;C-k&amp;gt; &amp;lt;C-w&amp;gt;k
map &amp;lt;C-l&amp;gt; &amp;lt;C-w&amp;gt;l
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tired of clearing highlighted searches by searching for &amp;#x201C;ldsfhjkhgakjks&amp;#x201D;?  Use
this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
nmap &amp;lt;silent&amp;gt; ,/ :nohlsearch&amp;lt;CR&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;ins&gt;I used to have it mapped to &lt;code&gt;:let @/=""&amp;lt;CR&amp;gt;&lt;/code&gt;, but some users kindly pointed
out that it is better to use &lt;code&gt;:nohlsearch&lt;/code&gt;, because it keeps the search history
intact.&lt;/ins&gt;&lt;/p&gt;
&lt;p&gt;It clears the search buffer when you press &lt;code&gt;,/&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Finally, a trick by &lt;a href="http://forrst.com/posts/Use_w_to_sudo_write_a_file_with_Vim-uAN"&gt;Steve
Losh&lt;/a&gt; for when
you forgot to &lt;code&gt;sudo&lt;/code&gt; before editing a file that requires root privileges
(typically &lt;code&gt;/etc/hosts&lt;/code&gt;).  This lets you use &lt;code&gt;w!!&lt;/code&gt; to do that &lt;strong&gt;after&lt;/strong&gt; you
opened the file already:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
cmap w!! w !sudo tee % &amp;gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Use plugins&lt;/h2&gt;
&lt;p&gt;Ah, finally.  Arrived at the magical stuff that is Vim plugins.  This is a
listing of the Vim plugins I depend on most and that really offer added value
when you work with Vim every day.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/08/textmate.png" class="right" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Almost any person I know who owns a Mac has at least tried or purchased the
&lt;a href="http://macromates.com/"&gt;TextMate&lt;/a&gt; editor.  It is a great programmer&amp;#x2019;s editor
that has a lot of nice features, but of course, lacks Vim-style navigation :)&lt;/p&gt;
&lt;p&gt;&lt;ins&gt;Some of its features have inspired Vim plugin developers to clone the
awesomeness.  TextMate&amp;#x2019;s best two features (super-quick file opening and
snippets) have been &amp;#x201C;ported&amp;#x201D; to Vim plugins.&lt;/ins&gt;&lt;/p&gt;
&lt;h3 id="command-t"&gt;
&lt;ins&gt;Command-T: TextMate-style file opening&lt;/ins&gt; &lt;del&gt;NERDTree explorer&lt;/del&gt;
&lt;/h3&gt;
&lt;p&gt;&lt;!-- Old NERDTree explorer stuff {{{ --&gt;
&lt;div class="del"&gt;&lt;/div&gt;
&lt;p&gt;The NERDTree plugin is an absolute must for almost any Vim user.  For those
who don&amp;#x2019;t know it yet, NERDTree is a visual file browser that allows you to
quickly open files by navigating onto it and pressing Return.&lt;/p&gt;
&lt;p&gt;You can open the NERDTree using the &lt;code&gt;:NERDTree&lt;/code&gt; command, or by using
&lt;code&gt;:NERDTreeToggle&lt;/code&gt;.  To close the tree window, use &lt;code&gt;:NERDTreeClose&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/08/nerdtree.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;I have I&amp;#x2019;ve mapped some shortcuts to these commands, for quick access to the list:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
nmap ,n :NERDTreeCloseCR:NERDTreeToggleCR
nmap ,m :NERDTreeCloseCR:NERDTreeFindCR
nmap ,N :NERDTreeCloseCR
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can add quick bookmarks to directories that you often visit (like project
directories), which works really well.  I have configured the following
settings, which tells the plugin where the bookmark file is, which extensions
to ignore, to show hidden files and to quit on open (which I like to have on,
to have screen real estate for my code):&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-vim"&gt;
" Store the bookmarks file
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")

" Don't display these kinds of files
let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.py\$class$', '\.obj$',
            \ '\.o$', '\.so$', '\.egg$', '^\.git$' ]

let NERDTreeShowBookmarks=1       " Show the bookmarks table on startup
let NERDTreeShowFiles=1           " Show hidden files, too
let NERDTreeShowHidden=1
let NERDTreeQuitOnOpen=1          " Quit on opening files from the tree
let NERDTreeHighlightCursorline=1 " Highlight the selected entry in the tree
let NERDTreeMouseMode=2           " Use a single click to fold/unfold directories
                                  " and a double click to open files
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can add quick bookmarks to directories that you often visit (like project
directories), which works really well, too.&lt;/p&gt;
&lt;p&gt;More documentation available at: the &lt;a href="http://www.vim.org/scripts/script.php?script_id=1658"&gt;plugin
page&lt;/a&gt;.&lt;/p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;!-- }}} --&gt;
&lt;div class="ins"&gt;&lt;/div&gt;
&lt;p&gt;I used to have a whole discussion on the &lt;a href="http://www.vim.org/scripts/script.php?script_id=1658"&gt;NERDTree
explorer&lt;/a&gt; plugin here, but
I was pointed towards &lt;a href="https://wincent.com/products/command-t"&gt;Command-T&lt;/a&gt; by a
few readers.  Once I tried that plugin for a few minutes, it became clear that
there would be no need for NERDTree anymore.&lt;/p&gt;
&lt;p&gt;The name Command-T is a reference to the original shortcut for &amp;#x201C;Go to File&amp;#x201D; in
TextMate, which opens the quick file opener.  Setting up this plugin is a bit
more tricky than usual, because some files need to be compiled, but the
instructions on the website are very clear and simple.  There&amp;#x2019;s even a
screencast for Windows users.&lt;/p&gt;
&lt;p&gt;The plugin registers itself under &lt;code&gt;leadert&lt;/code&gt; (in my case that&amp;#x2019;s &lt;code&gt;,t&lt;/code&gt;).  And if
it does, it shows a list of all the files from the current directory and a
search box in which you can type any character progression.  By typing more
characters, the list of files is narrowed down to contain only files that have
that string as a subset.  But here&amp;#x2019;s the real added value: you can type any
sequence of characters that are in the file&amp;#x2019;s path, they don&amp;#x2019;t have to be
subsequent characters.  For example, if you have the following list of files:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;foo/bar.py
foo/qux.py
tests/test_foo/test_bar.py
tests/test_foo/test_qux.py&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You could type the sequence &lt;strong&gt;fb&lt;/strong&gt; to select the file &lt;code&gt;foo/bar.py&lt;/code&gt;, or &lt;strong&gt;tfb&lt;/strong&gt; to
select &lt;code&gt;tests/test_foo/test_bar.py&lt;/code&gt;.  As you can imagine, this is a huge time
saver.  There is much more goodness in there.  For that, please refer to
Wincent&amp;#x2019;s screencasts, or his website.&lt;/p&gt;
&lt;p&gt;You can download the plugin at
&lt;a href="http://www.vim.org/scripts/script.php?script_id=3025"&gt;vim.org&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: On Vim instances that don&amp;#x2019;t have Ruby support enabled (type &lt;code&gt;:version&lt;/code&gt;
to check this), the Commant-T plugin won&amp;#x2019;t work.  If it isn&amp;#x2019;t an option to
recompile Vim to add Ruby support, the &lt;a href="http://www.vim.org/scripts/script.php?script_id=1658"&gt;NERDTree
explorer&lt;/a&gt; still is a good
alternative.&lt;/p&gt;
&lt;/p&gt;
&lt;h3&gt;Snipmate: TextMate-style snippets for Vim&lt;/h3&gt;
&lt;p&gt;Another killer feature of TextMate are the intelligent snippets: you
type some text, press Tab and TextMate creates a snippet for you, with
placeholders at key positions within the snippet.  The first placeholder is
selected, your overwrite it with the text you want, then press Tab to select
the second placeholder, etc.  This lets you enter code super fast.&lt;/p&gt;
&lt;p&gt;Now it&amp;#x2019;s available to us Vim users, too, in the form of the &lt;a href="http://www.vim.org/scripts/script.php?script_id=2540"&gt;snipMate
plugin&lt;/a&gt; (dubbed after
TextMate).  There&amp;#x2019;s a great &lt;a href="http://vimeo.com/3535418"&gt;introductory screencast&lt;/a&gt;
to get you excited about it.&lt;/p&gt;
&lt;h4&gt;Writing your own snippets&lt;/h4&gt;
&lt;p&gt;There are already lots of specific language &lt;del&gt;plugins&lt;/del&gt;
&lt;ins&gt;&lt;a href="http://github.com/scrooloose/snipmate-snippets"&gt;snippets&lt;/a&gt;&lt;/ins&gt; for snipMate
available, but writing your own is simple in case you ever miss functionality.
Just create a file called &lt;code&gt;~/.vim/snippets/foo.snippet&lt;/code&gt;, where &lt;code&gt;foo&lt;/code&gt; is the
filetype you want to load the snippets for.&lt;/p&gt;
&lt;p&gt;Then, declare your snippets.  That&amp;#x2019;s really as easy as this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;snippet def
    def ${1:fname}(${2:arg}):
        ${3:pass}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you declare this, you can simply use &lt;code&gt;defTab&lt;/code&gt; and it will expand to a
Python function definition.  The &lt;code&gt;${1:fname}&lt;/code&gt; means put the first placeholder
at this position, and fill it with a default value of &amp;#x201C;fname&amp;#x201D;.&lt;/p&gt;
&lt;h3&gt;Other cool plugins&lt;/h3&gt;
&lt;p&gt;In order to make the article not any more longer than it already is, here&amp;#x2019;s a
list of other plugins that are really worth checking out (I use each of them
regularly):&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
&lt;a href="http://www.vim.org/scripts/script.php?script_id=1408"&gt;localrc&lt;/a&gt;: lets you load
  specific Vim settings for any file in the same directory (or a subdirectory
  thereof).  Comes in super handy for project-wide settings.&lt;/li&gt;
	&lt;li&gt;&lt;ins&gt;&lt;a href="http://github.com/rstacruz/sparkup"&gt;Sparkup&lt;/a&gt;: write &lt;span class="caps"&gt;HTML&lt;/span&gt; lightning fast by
  jotting down a &amp;#x201C;&lt;span class="caps"&gt;CSS&lt;/span&gt; selector&amp;#x201D;-like line and pressing a shortcut.  Super time
  saver when you edit &lt;span class="caps"&gt;HTML&lt;/span&gt; manually. Go see &lt;a href="http://www.youtube.com/watch?v=Jw3jipcenKc"&gt;the demo
  video&lt;/a&gt;.&lt;/ins&gt;&lt;/li&gt;
	&lt;li&gt;&lt;ins&gt;&lt;a href="http://www.vim.org/scripts/script.php?script_id=1234"&gt;YankRing&lt;/a&gt;: quickly
  cycle through your registers when pasting, to select the appropriate paste.
  How often have you &amp;#x201C;cut&amp;#x201D; a line, then &amp;#x201C;deleted&amp;#x201D; a line, only to find the
  &amp;#x201C;deleted&amp;#x201D; line in your last paste register?&lt;/ins&gt;&lt;/li&gt;
	&lt;li&gt;
&lt;a href="http://www.vim.org/scripts/script.php?script_id=1624"&gt;Pastie&lt;/a&gt;: lets you
  visually select a piece of code and submit it to
  &lt;a href="http://pastie.org"&gt;pastie.org&lt;/a&gt;.  It even has automatic filetype recognition.&lt;/li&gt;
	&lt;li&gt;
&lt;a href="http://www.vim.org/scripts/script.php?script_id=1697"&gt;surround&lt;/a&gt;: quickly
  change surroundings of a piece of code. For example, to change &lt;code&gt;dict(mykey)&lt;/code&gt;
  into &lt;code&gt;dict[mykey]&lt;/code&gt;, put the cursor on &lt;code&gt;mykey&lt;/code&gt;, then type &lt;code&gt;cs(]&lt;/code&gt; (change
  surroundings from &lt;code&gt;()&lt;/code&gt; to &lt;code&gt;[]&lt;/code&gt;).&lt;/li&gt;
	&lt;li&gt;
&lt;a href="http://www.vim.org/scripts/script.php?script_id=2136"&gt;repeat&lt;/a&gt;: lets you
  repeat the changing of surroundings using the default Vim repeat operator &lt;code&gt;.&lt;/code&gt;
  (dot).&lt;/li&gt;
	&lt;li&gt;
&lt;a href="http://www.vim.org/scripts/script.php?script_id=1545"&gt;abolish&lt;/a&gt;: bulk-define
  autocorrections (abbreviations) for many conjugations of words and smart
  conversion of words from snake_case (&lt;code&gt;crs&lt;/code&gt;) to camelCase (&lt;code&gt;cr_&lt;/code&gt;) or MixedCase
  (&lt;code&gt;crm&lt;/code&gt;) to UPPER_CASE (&lt;code&gt;cru&lt;/code&gt;) and vice versa.&lt;/li&gt;
	&lt;li&gt;&lt;ins&gt;&lt;a href="http://www.vim.org/scripts/script.php?script_id=2050"&gt;LustyJuggler&lt;/a&gt;: a quick
  buffer switcher and a great companion to Command-T. See &lt;a href="http://lococast.net/archives/185"&gt;this
  screencast&lt;/a&gt; (Lococast) to get excited.&lt;/ins&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="ins"&gt;
&lt;h3&gt;Other resources&lt;/h3&gt;
&lt;p&gt;Some of the resources from where I have collected inspiration for my &lt;code&gt;.vimrc&lt;/code&gt;
file, plugins, and tricks:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://vimcasts.org/"&gt;Vimcasts&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://lococast.net/"&gt;Lococast&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;
&lt;a href="http://vimeo.com/user1690209/videos"&gt;Derek Wyatt&amp;#x2019;s videos&lt;/a&gt; (on Vimeo)&lt;/li&gt;
	&lt;li&gt;&lt;ins&gt;Steve Losh blogged about &lt;a href="http://stevelosh.com/blog/2010/09/coming-home-to-vim/"&gt;moving back to
  Vim&lt;/a&gt; and has some great
  tips and tricks.&lt;/ins&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;I hope you like these tips.  Please add your comments below if you do, or if
you have any Vim improvements or tips you&amp;#x2019;d like to bring on yourself.  &lt;ins&gt;You can
have a look at my full Vim configuration in my
&lt;a href="http://github.com/nvie/vimrc"&gt;Github repo&lt;/a&gt;.&lt;/ins&gt;&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;A few weeks ago, I felt inspired by articles from &lt;a href="http://jeffkreeftmeijer.com/2010/stumbling-into-vim/"&gt;Jeff
Kreeftmeijer&lt;/a&gt; and &lt;a href="http://lucumr.pocoo.org/2010/7/29/sharing-vim-tricks"&gt;Armin
Ronacher&lt;/a&gt;.  I took some
time to configure and fine-tune my Vim environment.  A lot of new stuff made it
into my &lt;code&gt;.vimrc&lt;/code&gt; file and my &lt;code&gt;.vim&lt;/code&gt; directory.  This blog post is a summary
describing what I&amp;#8217;ve added and how I use it in my daily work.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-09-13:/posts/a-whole-new-blog/</id>
    <title type="html">A whole new blog</title>
    <published>2010-09-12T22:00:00Z</published>
    <updated>2010-09-12T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/a-whole-new-blog/" />
    <content type="html">&lt;p&gt;Finally, I&amp;#x2019;ve made the move to a static blog engine!  I&amp;#x2019;m using
&lt;a href="http://nanoc.stoneship.org/"&gt;nanoc&lt;/a&gt; now (bye bye WordPress). nanoc is a very
flexible and customizable static site generator, written by &lt;a href="http://twitter.com/ddfreyne"&gt;Denis
Defreyne&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As with all static site generators, nanoc lets you write your source files in a
simple markup language.  Out of the box, nanoc offers you the choice of using
Markdown, Textile, reStructuredText or plain &lt;span class="caps"&gt;HTML&lt;/span&gt; (with or without embedded
Ruby).  In fact, nanoc is nothing more than a generator honoring a &lt;code&gt;Rules&lt;/code&gt;-file
that tells it how to compile, layout and route the site&amp;#x2019;s items.&lt;/p&gt;
&lt;h2&gt;Compiling items&lt;/h2&gt;
&lt;p&gt;An &amp;#x201C;item&amp;#x201D; is a file on your website.  It can be any kind of file, like a web
site page (&lt;span class="caps"&gt;HTML&lt;/span&gt;), an image, a JavaScript or &lt;span class="caps"&gt;CSS&lt;/span&gt; file or an &lt;span class="caps"&gt;RSS&lt;/span&gt; feed.  During
the compile phase, you specify which sequential actions should be performed on
the &lt;em&gt;content&lt;/em&gt; of that item.  These actions are called &lt;strong&gt;filters&lt;/strong&gt;.  Some examples
of filters are an embedded ruby filter, a
&lt;a href="http://redcloth.org/"&gt;Textile-to-&lt;span class="caps"&gt;HTML&lt;/span&gt;&lt;/a&gt; converter, a &lt;a href="http://lesscss.org/"&gt;less&lt;/a&gt;
compiler, or minify &lt;a href="http://code.google.com/p/rainpress/"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/a&gt;.  Filters can be
chained, for example:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ruby"&gt;
compile '/static/css/*/' do
    # compress CSS :)
    filter :less
    filter :rainpress
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which turns &lt;code&gt;.less&lt;/code&gt;-files into compressed &lt;span class="caps"&gt;CSS&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/09/less2css.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Any filter you can imagine, nanoc can handle. nanoc comes with a lot of filters
&lt;a href="http://nanoc.stoneship.org/docs/4-basic-concepts/#filters"&gt;out of the box&lt;/a&gt;, but
even &lt;a href="http://nanoc.stoneship.org/docs/5-advanced-concepts/#writing-filters"&gt;writing your own&lt;/a&gt;
filters really is a piece of cake.&lt;/p&gt;
&lt;h2&gt;Routing items&lt;/h2&gt;
&lt;p&gt;After compiling (i.e. transforming content through filters) comes the routing
of the items.  This is a means of assigning file names to compiled content.
nanoc calculates default files names from the input, but you can use this to
influence the default naming.  A special case is where you set the route to
&lt;code&gt;Nil&lt;/code&gt; which doesn&amp;#x2019;t write the file at all.  I use this to test draft posts
locally, like this (oh, did I mention the &lt;code&gt;Rules&lt;/code&gt; file is 100% Ruby?):&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ruby"&gt;
route '/posts/*/' do
    if $include_drafts or @item[:published] then
        '/posts/' + @item.slug + '/index.html'
    end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Laying out items&lt;/h2&gt;
&lt;p&gt;Finally, layouts are applied.  Layouts are kind of templates that can be used
to &amp;#x201C;frame&amp;#x201D; the item&amp;#x2019;s contents.  This is typically used for &lt;span class="caps"&gt;HTML&lt;/span&gt; files only,
but isn&amp;#x2019;t limited to it.  For example, the blog posts are compiled into
(partial) &lt;span class="caps"&gt;HTML&lt;/span&gt;, and the layout rules put the site&amp;#x2019;s container &lt;span class="caps"&gt;HTML&lt;/span&gt; around it,
adding &lt;span class="caps"&gt;CSS&lt;/span&gt; styling, jQuery scripts, the header, sidebars and footer and Google
Analytics tracking (these go for each page).  There&amp;#x2019;s a special extra layout
rule for blog post pages, which additionally adds Disqus comments.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;Each build of this blog also automatically:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Converts &lt;a href="http://redcloth.org/"&gt;Textile&lt;/a&gt; content to &lt;span class="caps"&gt;HTML&lt;/span&gt;
&lt;/li&gt;
	&lt;li&gt;Highlights syntax using &lt;a href="http://pygments.org/"&gt;pygments&lt;/a&gt;
&lt;/li&gt;
	&lt;li&gt;Converts &lt;a href="http://lesscss.org/"&gt;less&lt;/a&gt; to &lt;span class="caps"&gt;CSS&lt;/span&gt;
&lt;/li&gt;
	&lt;li&gt;Minifies &lt;a href="http://code.google.com/p/rainpress/"&gt;&lt;span class="caps"&gt;CSS&lt;/span&gt;&lt;/a&gt;
&lt;/li&gt;
	&lt;li&gt;Minifies &lt;a href="http://code.google.com/closure/compiler/"&gt;JavaScript&lt;/a&gt;
&lt;/li&gt;
	&lt;li&gt;
&lt;a href="http://www.graphicsmagick.org/convert.html"&gt;Downsizes&lt;/a&gt; source images&lt;/li&gt;
	&lt;li&gt;Generates redirect pages for alternative (old-style) URL&amp;#x2019;s (for user that have
  existing bookmarks to old WordPress URL&amp;#x2019;s)&lt;/li&gt;
	&lt;li&gt;Generates a new blog post
  &lt;a href="http://nanoc.stoneship.org/docs/api/3.1/Nanoc3/Helpers/Blogging.html"&gt;&lt;span class="caps"&gt;RSS&lt;/span&gt; feed&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In short, now nanoc is fully configured to my wishes, I can simply focus on
writing &lt;strong&gt;blog content&lt;/strong&gt;, without preparing image content (it is done
automatically), and without having to choose between either a &amp;#x201C;&lt;span class="caps"&gt;WYSIWYG&lt;/span&gt;&amp;#x201D; editor
or writing &lt;span class="caps"&gt;HTML&lt;/span&gt; manually.  And I can do it in an offline fashion, too, which
was one my main complaints about WordPress.&lt;/p&gt;
&lt;p&gt;So I&amp;#x2019;m happy.&lt;/p&gt;
&lt;p&gt;Oh, and since I have been converting my blog anyway, I also created a new look
and feel for it.  I hope you like it.  Feel free to comment.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;Finally, I&amp;#8217;ve made the move to a static blog engine!  I&amp;#8217;m using
&lt;a href="http://nanoc.stoneship.org/"&gt;nanoc&lt;/a&gt; now. nanoc is a very
flexible and customizable static site generator, written by &lt;a href="http://twitter.com/ddfreyne"&gt;Denis
Defreyne&lt;/a&gt;.  As with all static site generators,
nanoc lets you write your source files in a simple markup language.
However, nanoc is much more flexible and customizable than most of the
others out there.  Let me show you a sneak peak of its internals.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-03-04:/posts/an-upgrade-of-gitflow/</id>
    <title type="html">An upgrade of gitflow</title>
    <published>2010-03-03T23:00:00Z</published>
    <updated>2010-03-03T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/an-upgrade-of-gitflow/" />
    <content type="html">&lt;p&gt;Last week, I silently tagged &lt;a href="http://github.com/nvie/gitflow/tree/0.2"&gt;gitflow
0.2&lt;/a&gt;. The most important changes since
0.1 are:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Order of arguments changed to have a more &amp;#x201C;gitish&amp;#x201D; subcommand structure. For
  example, you now say:
  &lt;pre&gt;&lt;code&gt;git flow feature start myfeature&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
	&lt;li&gt;Better initializer. &lt;code&gt;git flow init&lt;/code&gt; now prompts interactively to set up a
  gitflow enabled repo.&lt;/li&gt;
	&lt;li&gt;Added a command to list all feature/release/hotfix/support branches, e.g.:
  &lt;pre&gt;&lt;code&gt;git flow feature list&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
	&lt;li&gt;Made all merge/rebase operations failsafe, providing a non-destructive
  workflow in case of merge conflicts.&lt;/li&gt;
	&lt;li&gt;Easy diff&amp;#x2019;ing of all changes on a specific (or the current) feature branch:
  &lt;pre&gt;&lt;code&gt;git flow feature diff [feature]&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
	&lt;li&gt;Add support for feature branch rebasing:
  &lt;pre&gt;&lt;code&gt;git flow feature rebase&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
	&lt;li&gt;Some subactions now take name prefixes as their arguments, for convenience.
  For example, if you have feature branches called &amp;#x201C;experimental&amp;#x201D;,
  &amp;#x201C;refactoring&amp;#x201D; and &amp;#x201C;feature-X&amp;#x201D;, you could say:
  &lt;pre&gt;&lt;code&gt;git flow feature finish ref&lt;/code&gt;&lt;/pre&gt;
  And gitflow will know you mean the &amp;#x201C;refactoring&amp;#x201D; feature branch.&lt;br&gt;
  These actions are: &lt;code&gt;finish&lt;/code&gt;, &lt;code&gt;diff&lt;/code&gt; and &lt;code&gt;rebase&lt;/code&gt;.&lt;/li&gt;
	&lt;li&gt;Much better overall sanity checking.&lt;/li&gt;
	&lt;li&gt;Better portability (&lt;span class="caps"&gt;POSIX&lt;/span&gt; compliant code)&lt;/li&gt;
	&lt;li&gt;Better (more portable) flag parsing using Kate Ward&amp;#x2019;s
  &lt;a href="http://code.google.com/p/shflags/"&gt;shFlags&lt;/a&gt;.&lt;/li&gt;
	&lt;li&gt;Improved installer. To install &lt;code&gt;git flow&lt;/code&gt; as a first-class Git subcommand,
  simply type:
  &lt;pre&gt;&lt;code&gt;sudo make install&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Major and minor bug fixes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That&amp;#x2019;s all for now.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;Last week, I silently tagged &lt;a href="http://github.com/nvie/gitflow/tree/0.2"&gt;gitflow
0.2&lt;/a&gt;. These are the most important
changes since 0.1.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-03-03:/posts/unexpected-side-effects-in-python-classes/</id>
    <title type="html">Unexpected side effects in Python classes</title>
    <published>2010-03-02T23:00:00Z</published>
    <updated>2010-03-02T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/unexpected-side-effects-in-python-classes/" />
    <content type="html">&lt;p&gt;Today, I lost several hours while debugging a language implementation detail
in Python that I did not know of and that really feels counterintuitive and
dangerous to me.&lt;/p&gt;
&lt;p&gt;I was writing unit tests for a Python class that I was implementing, when one
of the tests that had repeatedly been passing suddenly failed. Moreover, the
failing test case was really for testing some completely unrelated piece of
functionaly. This simply could not be broken!&lt;/p&gt;
&lt;p&gt;After at least an hour of scrutinizing the code, I was able to distill the
real problem, which I think is summarized here in the most compact way:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-python"&gt;
class Foo:
  x = {}
  
  def __init__(self, id):
    self.x[id] = id

f1 = Foo(5)
print f1.x     # {5:5}, as expected
f2 = Foo(6)
print f2.x     # {5:5,6:6} ?!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Creating a simple &lt;code&gt;Foo&lt;/code&gt; instance twice exposes the ugly side effect: the
second &lt;code&gt;Foo&lt;/code&gt; instance has an already initialized &lt;code&gt;x&lt;/code&gt; instance variable when
the constructor enters! Yuck! Moreover, now, too:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-python"&gt;
print f1.x     # {5:5,6:6}, too!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Apparently, the &lt;code&gt;x&lt;/code&gt; &amp;#x201C;instance variable&amp;#x201D; is a shared object, much like a global
or class variable.&lt;/p&gt;
&lt;p&gt;To be even more confusing, this doesn&amp;#x2019;t seem to hold for basic data types. For
example, change the dictionary to an integer, and the example behaves as
expected:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-python"&gt;
class Foo:
  x = 3

  def __init__(self, id):
    self.x = id

f1 = Foo(5)
print f1.x     # 5, as expected
f2 = Foo(6)
print f2.x     # 6, as expected
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The behaviour demystified&lt;/h2&gt;
&lt;p&gt;The real confusion here is that I was thinking that I was creating &amp;#x201C;instance
variables&amp;#x201D;, like you would in C++ or Java. As the &lt;a href="http://docs.python.org/tutorial/classes.html#instance-objects"&gt;Python
documentation&lt;/a&gt;
mentions:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#x201C;data attributes correspond to [&amp;#x2026;] to data members in C++. Data
attributes need not be declared; like local variables, they spring into
existence when they are first assigned to.&amp;#x201D;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Yes, I knew that, but nonetheless my real-world class is much bigger than &lt;code&gt;Foo&lt;/code&gt;
and I wanted an explicit overview on which instance variables are in this
class. Hence the data member.&lt;/p&gt;
&lt;p&gt;However, this is not how the Python interpreter processes Python code. In fact,
upon class definition, the statement &lt;code&gt;x = {}&lt;/code&gt; is executed within the scope of
the newly defined class. To prove this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-python"&gt;
class Bar:
  x = {}

print Bar.x     # {}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Even without a constructor or instance variable, we can access the data member
&lt;code&gt;x&lt;/code&gt;. Of course. Now this suddenly seems obvious.&lt;/p&gt;
&lt;p&gt;But what about our instance variables? Apparently, when we create a new
instance of &lt;code&gt;Bar&lt;/code&gt;, the instance data member &lt;code&gt;x&lt;/code&gt; is initially &lt;em&gt;pointing to the
same object&lt;/em&gt; as the class data member &lt;code&gt;x&lt;/code&gt;. The following example proves this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-python"&gt;
class Foo:
  x = {}
  
  def __init__(self, id):
    self.x = { id: id }

f1 = Foo(5)
print f1.x     # { 5:5 }, as expected
f2 = Foo(6)
print f2.x     # { 6:6 }, as expected
print Foo.x    # {}, didn't intend this!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This example also demonstrates the subtlety of the accidentally discovered
side-effect. Remember how we were changing the dictionary in our initial
example? &lt;code&gt;self.x[id] = id&lt;/code&gt;&lt;br&gt;
The instance data member was pointing to the same object as the class data
member. By updating the dictionary, the single dictionary object was changed,
causing unwanted side effects in other class instances.&lt;/p&gt;
&lt;p&gt;In the listing above, &lt;code&gt;x&lt;/code&gt; is forced to point to a new dictionary by the
assignment &lt;code&gt;self.x = { id:id }&lt;/code&gt;. In other words, &lt;code&gt;x&lt;/code&gt; points to a new object!
This also perfectly explains why the integer example worked&amp;#x2014;it&amp;#x2019;s the same kind
of assignment.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;To summarize, I learned some important lessons today:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;All the time, I have been creating class data members in all my classes,
  without knowing this.&lt;/li&gt;
	&lt;li&gt;I initialized those members to default values, effectively creating useless
  objects that are never accessed and just claiming memory.&lt;/li&gt;
	&lt;li&gt;Although it can be explained, a seemingly innocent statement like &lt;code&gt;x = {}&lt;/code&gt;
  can have very ugly side effects. Be warned!&lt;/li&gt;
	&lt;li&gt;Never underestimate the power of unit tests. It is absolutely worth the
  investment.&lt;/li&gt;
&lt;/ul&gt;</content>
    <summary type="html">&lt;p&gt;Today, I lost several hours while debugging a language implementation detail
in Python that I did not know of and that really feels counterintuitive and
dangerous to me.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-01-26:/posts/gitflow-01-released/</id>
    <title type="html">gitflow 0.1 released</title>
    <published>2010-01-25T23:00:00Z</published>
    <updated>2010-01-25T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/gitflow-01-released/" />
    <content type="html">&lt;p&gt;After the overwhelming attention and feedback on the &lt;a href="http://nvie.com/archives/323"&gt;Git branching model
post&lt;/a&gt;, a general consensus was that this workflow would benefit
from some form of proper scriptability. The workflow works seamlessly if you
perform the steps involved manually, but hey&amp;#x2026; manually is manually, really.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;ins&gt;&lt;strong&gt;&lt;span class="caps"&gt;UPDATE&lt;/span&gt; 2/4/2010&lt;/strong&gt;:
Anyone reading this: I recommend &lt;span class="caps"&gt;NOT&lt;/span&gt; &lt;span class="caps"&gt;USING&lt;/span&gt; this very early release, but to
jump on the &lt;a href="http://github.com/nvie/gitflow/tree/develop"&gt;current develop tip&lt;/a&gt;,
which is much more mature. Release 0.2 is coming very soon.&lt;/ins&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;An assisting tool (dubbed &lt;code&gt;gitflow&lt;/code&gt;) was therefore created to provide simple,
high-level commands to adopt the workflow into your own software development
process. It&amp;#x2019;s free and it&amp;#x2019;s open source. Feel free to contribute to it if you
like.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Fork me on Github:
&lt;a href="http://github.com/nvie/gitflow"&gt;http://github.com/nvie/gitflow&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Since this morning, the first working &lt;a href="http://github.com/nvie/gitflow/downloads"&gt;release
0.1&lt;/a&gt; was tagged, albeit very basic.&lt;/p&gt;
&lt;h3&gt;A quick walkthrough&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;gitflow&lt;/code&gt; script essentially features six subcommands: paired start/finish
commands for managing the different types of branches from the originating
article:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Feature branches:
	&lt;ul&gt;
		&lt;li&gt;
&lt;code&gt;gitflow start feature&lt;/code&gt; &lt;em&gt;&lt;code&gt;myfeature&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
		&lt;li&gt;
&lt;code&gt;gitflow finish feature&lt;/code&gt; &lt;em&gt;&lt;code&gt;myfeature&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
	&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Release branches:
	&lt;ul&gt;
		&lt;li&gt;
&lt;code&gt;gitflow start release&lt;/code&gt; &lt;em&gt;&lt;code&gt;version-id&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
		&lt;li&gt;
&lt;code&gt;gitflow finish release&lt;/code&gt; &lt;em&gt;&lt;code&gt;version-id&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
	&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
	&lt;li&gt;Hotfix branches:
	&lt;ul&gt;
		&lt;li&gt;
&lt;code&gt;gitflow start hotfix&lt;/code&gt; &lt;em&gt;&lt;code&gt;version-id&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
		&lt;li&gt;
&lt;code&gt;gitflow finish hotfix&lt;/code&gt; &lt;em&gt;&lt;code&gt;version-id&lt;/code&gt;&lt;/em&gt;
&lt;/li&gt;
	&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each of these scripts exactly reports what actions were taken and what
follow-up actions are required by the user. This output will be polished in
future versions to improve the
&lt;a href="http://en.wikipedia.org/wiki/User_experience_design"&gt;UX&lt;/a&gt;. An example output:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ gitflow finish feature foo
Branches 'develop' and 'origin/develop' have diverged.
And local branch 'develop' is ahead of 'origin/develop'.
Switched to branch "develop"
Your branch is ahead of 'origin/develop' by 12 commits.
Merge made by recursive.
 README |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Deleted branch foo (cd3effb).
 
Summary of actions:
- The feature branch 'foo' was merged into 'develop'
- Feature branch 'foo' has been removed
- You are now on branch 'develop'
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Limitations&lt;/h3&gt;
&lt;p&gt;The script is very limited at the moment yet, but future versions will fix
that, too. Some of the main limitations:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Branch names (&lt;code&gt;master&lt;/code&gt;, &lt;code&gt;develop&lt;/code&gt;) and the remote repo name (&lt;code&gt;origin&lt;/code&gt;) are
  currently fixed.&lt;/li&gt;
	&lt;li&gt;There is no support for dealing with merge conflicts yet.&lt;/li&gt;
	&lt;li&gt;There is no support for &lt;code&gt;support-*&lt;/code&gt; branches (see the &lt;a href="http://nvie.com/archives/323#comment-185"&gt;original
  comment&lt;/a&gt; that proposed this extension)&lt;/li&gt;
	&lt;li&gt;There is no documentation.&lt;/li&gt;
	&lt;li&gt;There is no installer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, as this post is written, some of the limitations are already taken
care of by community members. Power to the open source!&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;After the overwhelming attention and feedback on the &lt;a href="/archives/323"&gt;Git branching model
post&lt;/a&gt;, a general consensus was that this workflow would
benefit from some form of proper scriptability. This post proposes the
initial version of a tool I called
&lt;a href="http://github.com/nvie/gitflow"&gt;git-flow&lt;/a&gt;.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-01-13:/posts/building-git-from-scratch-on-snow-leopard/</id>
    <title type="html">Building Git from scratch on Snow Leopard</title>
    <published>2010-01-12T23:00:00Z</published>
    <updated>2010-01-12T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/building-git-from-scratch-on-snow-leopard/" />
    <content type="html">&lt;p&gt;When you try to build Git &lt;a href="http://github.com/git/git"&gt;from scratch&lt;/a&gt; on a Snow
Leopard machine, you may have ran into the following problem:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git clone git://github.com/git/git.git
Initialized empty Git repository in /Users/nvie/git/.git/
remote: Counting objects: 111619, done.
remote: Compressing objects: 100% (28007/28007), done.
remote: Total 111619 (delta 82192), reused 111264 (delta 81852)
Receiving objects: 100% (111619/111619), 27.60 MiB | 531 KiB/s, done.
Resolving deltas: 100% (82192/82192), done.
$ cd git
$ make prefix=/usr/local/bin/git
GIT_VERSION = 1.6.2.rc0.90.g0753
    * new build flags or prefix
    CC fast-import.o
    CC abspath.o
    :
    :
ld: warning: in /opt/local/lib/libexpat.dylib, file is not of required architecture
    ...
ld: symbol(s) not found
collect2: ld returned 1 exit status
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, you have a pretty big change you are having an old Darwin ports
(&lt;a href="http://www.macports.org"&gt;macports&lt;/a&gt;) collection in use which has not yet been
upgraded to Snow Leopard&amp;#x2019;s new x64 architecture.&lt;/p&gt;
&lt;p&gt;There is, however, a simple solution to this, namely to have the &lt;code&gt;git&lt;/code&gt; build
ignore the Darwin ports, simply by adding the following parameter to the build:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ make NO_DARWIN_PORTS=1 prefix=/usr/local/bin/git
&lt;/code&gt;&lt;/pre&gt;</content>
    <summary type="html">&lt;p&gt;When you try to build Git &lt;a href="http://github.com/git/git"&gt;from scratch&lt;/a&gt; on a Snow
Leopard machine, you may have ran into the following problem:&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2010-01-05:/posts/a-successful-git-branching-model/</id>
    <title type="html">A successful Git branching model</title>
    <published>2010-01-04T23:00:00Z</published>
    <updated>2010-01-04T23:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/a-successful-git-branching-model/" />
    <content type="html">&lt;p&gt;In this post I present the development model that I&amp;#x2019;ve introduced for all of my
projects (both at work and private) about a year ago, and which has turned out
to be very successful. I&amp;#x2019;ve been meaning to write about it for a while now, but
I&amp;#x2019;ve never really found the time to do so&amp;#xA0;thoroughly, until now. I won&amp;#x2019;t talk
about any of the projects&amp;#x2019; details, merely about the branching strategy and
release management.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/12/Screen-shot-2009-12-24-at-11.32.03.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;It focuses around &lt;a href="http://git-scm.com"&gt;Git&lt;/a&gt; as the tool for the versioning of
all of our source code.&lt;/p&gt;
&lt;h2&gt;Why git?&lt;/h2&gt;
&lt;p&gt;For a thorough discussion on the pros and cons of Git compared to centralized
source code control systems, &lt;a href="http://whygitisbetterthanx.com/"&gt;see&lt;/a&gt;
&lt;a href="http://www.looble.com/git-vs-svn-which-is-better/"&gt;the&lt;/a&gt;
&lt;a href="http://git.or.cz/gitwiki/GitSvnComparsion"&gt;web&lt;/a&gt;. There are plenty of flame wars
going on there. As a developer, I prefer Git above all other tools around
today. Git really changed the way developers think of merging and branching.
From the classic &lt;span class="caps"&gt;CVS&lt;/span&gt;/Subversion world I came from, merging/branching has always
been considered a bit scary (&amp;#x201C;beware of merge conflicts, they bite you!&amp;#x201D;) and
something you only do every once in a while.&lt;/p&gt;
&lt;p&gt;But with Git, these actions are extremely cheap and simple, and they are
considered one of the core parts of your &lt;em&gt;daily&lt;/em&gt; workflow, really. For example,
in &lt;span class="caps"&gt;CVS&lt;/span&gt;/Subversion &lt;a href="http://svnbook.red-bean.com"&gt;books&lt;/a&gt;, branching and merging is
first discussed in the later chapters (for advanced users), while in
&lt;a href="http://book.git-scm.com"&gt;every&lt;/a&gt;
&lt;a href="http://pragprog.com/titles/tsgit/pragmatic-version-control-using-git"&gt;Git&lt;/a&gt;
&lt;a href="http://github.com/progit/progit"&gt;book&lt;/a&gt;, it&amp;#x2019;s already covered in chapter 3
(basics).&lt;/p&gt;
&lt;p&gt;As a consequence of its simplicity and repetitive nature, branching and merging
are no longer something to be afraid of. Version control tools are supposed to
assist in branching/merging more than anything else.&lt;/p&gt;
&lt;p&gt;Enough about the tools, let&amp;#x2019;s head onto the development model.  The model that
I&amp;#x2019;m going to present here is essentially no more than a set of procedures that
every team member has to follow in order to come to a managed software
development process.&lt;/p&gt;
&lt;h2&gt;Decentralized but centralized&lt;/h2&gt;
&lt;p&gt;The repository setup that we use and that works well with this branching model,
is that with a central &amp;#x201C;truth&amp;#x201D; repo. Note that this repo&amp;#xA0;is only&amp;#xA0;&lt;em&gt;considered&lt;/em&gt;
to be the central one (since Git is a &lt;span class="caps"&gt;DVCS&lt;/span&gt;, there is no such thing as a central
repo at a technical level).&amp;#xA0;We will refer to this repo as &lt;code&gt;origin&lt;/code&gt;, since this
name is familiar to all Git users.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/01/centr-decentr.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Each developer pulls and pushes to origin. But besides the centralized
push-pull relationships, each developer may also pull changes from other peers
to form sub teams. For example, this might be useful to work together with two
or more developers on a big new feature, before pushing the work in progress to
&lt;code&gt;origin&lt;/code&gt; prematurely. In the figure above, there are subteams of Alice and Bob,
Alice and David, and Clair and David.&lt;/p&gt;
&lt;p&gt;Technically, this means nothing more than that Alice has defined a Git remote,
named &lt;code&gt;bob&lt;/code&gt;, pointing to Bob&amp;#x2019;s repository, and vice versa.&lt;/p&gt;
&lt;h2&gt;The main branches&lt;/h2&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/12/bm002.png" class="right" alt=""&gt;&lt;/p&gt;
&lt;p&gt;At the core, the development model is greatly inspired by existing models out
there.&amp;#xA0;The central repo holds two main branches with an infinite lifetime:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;master&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;&lt;code&gt;develop&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code&gt;master&lt;/code&gt; branch at &lt;code&gt;origin&lt;/code&gt; should be familiar to every Git user.&amp;#xA0;Parallel
to the &lt;code&gt;master&lt;/code&gt; branch, another branch exists called &lt;code&gt;develop&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We consider &lt;code&gt;origin/master&lt;/code&gt; to be the main branch where the source code of
&lt;code&gt;HEAD&lt;/code&gt; always reflects a &lt;em&gt;production-ready&lt;/em&gt; state.&lt;/p&gt;
&lt;p&gt;We consider &lt;code&gt;origin/develop&lt;/code&gt; to be the main branch where the source code of
&lt;code&gt;HEAD&lt;/code&gt; always reflects a state with the latest delivered development changes
for the next release. Some would call this the &amp;#x201C;integration branch&amp;#x201D;. This is
where any automatic nightly builds are built from.&lt;/p&gt;
&lt;p&gt;When the source code in the &lt;code&gt;develop&lt;/code&gt; branch reaches a stable point and is
ready to be released, all of the changes should be merged back into &lt;code&gt;master&lt;/code&gt;
somehow and then tagged with a release number. How this is done in detail will
be discussed further on.&lt;/p&gt;
&lt;p&gt;Therefore, each time when changes are merged back into &lt;code&gt;master&lt;/code&gt;, this is a new
production release &lt;em&gt;by definition&lt;/em&gt;.&amp;#xA0;We tend to be very strict at this, so that
theoretically, we could use a Git hook script to automatically build and
roll-out our software to our production servers everytime there was a commit on
&lt;code&gt;master&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;Supporting branches&lt;/h2&gt;
&lt;p&gt;Next to the main branches &lt;code&gt;master&lt;/code&gt; and &lt;code&gt;develop&lt;/code&gt;, our development model uses a
variety of supporting branches to aid parallel development between team
members, ease tracking of features, prepare for production releases and to
assist in quickly fixing live production problems. Unlike the main branches,
these branches always have a limited life time, since they will be removed
eventually.&lt;/p&gt;
&lt;p&gt;The different types of branches we may use are:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Feature branches&lt;/li&gt;
	&lt;li&gt;Release branches&lt;/li&gt;
	&lt;li&gt;Hotfix branches&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each of these branches have a specific purpose and are bound to strict rules as
to which branches may be their originating branch and which branches must be
their merge targets. We will walk through them in a minute.&lt;/p&gt;
&lt;p&gt;By no means are these branches &amp;#x201C;special&amp;#x201D; from a technical perspective. The
branch types are categorized by how we &lt;em&gt;use&lt;/em&gt; them. They are of course plain old
Git branches.&lt;/p&gt;
&lt;h3&gt;Feature branches&lt;/h3&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/12/fb.png" class="right" alt=""&gt;&lt;/p&gt;
&lt;p&gt;May branch off from:&amp;#xA0;&lt;code&gt;develop&lt;/code&gt;&lt;br&gt;
Must merge back into:&amp;#xA0;&lt;code&gt;develop&lt;/code&gt;&lt;br&gt;
Branch naming convention: anything except&amp;#xA0;&lt;code&gt;master&lt;/code&gt;, &lt;code&gt;develop&lt;/code&gt;, &lt;code&gt;release-*&lt;/code&gt;,
or &lt;code&gt;hotfix-*&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Feature branches (or sometimes called topic branches) are used to develop new
features for the upcoming or a distant future release. When starting
development of a feature, the target release in which this feature will be
incorporated may well be unknown at that point. The essence of a feature branch
is that it exists as long as the feature is in development, but will eventually
be merged back into &lt;code&gt;develop&lt;/code&gt; (to definitely add the new feature to the
upcoming release) or discarded (in case of a disappointing experiment).&lt;/p&gt;
&lt;p&gt;Feature branches typically exist in developer repos only, not in &lt;code&gt;origin&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;Creating a feature branch&lt;/h4&gt;
&lt;p&gt;When starting work on a new feature, branch off from the &lt;code&gt;develop&lt;/code&gt; branch.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout -b myfeature develop
Switched to a new branch "myfeature"
&lt;/code&gt;&lt;/pre&gt;
&lt;h4&gt;Incorporating a finished feature on develop&lt;/h4&gt;
&lt;p&gt;Finished features may be merged into the &lt;code&gt;develop&lt;/code&gt; branch definitely add them
to the upcoming release:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout develop
Switched to branch 'develop'
$ git merge --no-ff myfeature
Updating ea1b82a..05e9557
(Summary of changes)
$ git branch -d myfeature
Deleted branch myfeature (was 05e9557).
$ git push origin develop
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;--no-ff&lt;/code&gt; flag causes the merge to always create a new commit object, even
if the merge could be performed with a fast-forward. This avoids losing
information about the historical existence of a feature branch and groups
together all commits that together added the feature. Compare:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/01/merge-without-ff.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;In the latter case, it is impossible to see from the Git history which of the
commit objects together have implemented a feature&amp;#x2014;you would have to manually
read all the log messages. Reverting a whole feature (i.e. a group of commits),
is a true headache in the latter situation, whereas it is easily done if the
&lt;code&gt;--no-ff&lt;/code&gt; flag was used.&lt;/p&gt;
&lt;p&gt;Yes, it will create a few more (empty) commit objects, but the gain is much
bigger that that cost.&lt;/p&gt;
&lt;p&gt;Unfortunately, I have not found a way to make &lt;code&gt;--no-ff&lt;/code&gt; the default behaviour
of &lt;code&gt;git merge&lt;/code&gt; yet, but it really should be.&lt;/p&gt;
&lt;h3&gt;Release branches&lt;/h3&gt;
&lt;p&gt;May branch off from:&amp;#xA0;&lt;code&gt;develop&lt;/code&gt;&lt;br&gt;
Must merge back into:&amp;#xA0;&lt;code&gt;develop&lt;/code&gt; and &lt;code&gt;master&lt;/code&gt;&lt;br&gt;
Branch naming convention: &lt;code&gt;release-*&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Release branches support preparation of a new production release.&amp;#xA0;They allow
for last-minute dotting of i&amp;#x2019;s and crossing t&amp;#x2019;s. Furthermore, they allow for
minor bug fixes and preparing meta-data for a release (version number, build
dates, etc.). By doing all of this work on a release branch, the &lt;code&gt;develop&lt;/code&gt;
branch is cleared to receive features for the next big release.&lt;/p&gt;
&lt;p&gt;The key moment to branch off a new release branch from &lt;code&gt;develop&lt;/code&gt; is when
develop (almost) reflects the desired state of the new release.&amp;#xA0;At least all
features that are targeted for the release-to-be-built must be merged in to
&lt;code&gt;develop&lt;/code&gt; at this point in time. All features targeted at future releases may
not&amp;#x2014;they must wait until after the release branch is branched off.&lt;/p&gt;
&lt;p&gt;It is exactly at the start of a release branch that the upcoming release gets
assigned a version number&amp;#x2014;not any earlier. Up until that moment, the &lt;code&gt;develop&lt;/code&gt;
branch reflected changes for the &amp;#x201C;next release&amp;#x201D;, but it is unclear whether that
&amp;#x201C;next release&amp;#x201D; will eventually become 0.3 or 1.0, until the release branch is
started. That decision is made on the start of the release branch and is
carried out by the project&amp;#x2019;s rules on version number bumping.&lt;/p&gt;
&lt;h4&gt;Creating a release branch&lt;/h4&gt;
&lt;p&gt;Release branches are created from the &lt;code&gt;develop&lt;/code&gt; branch. For example, say
version 1.1.5 is the current production release and we have a big release
coming up. The state of &lt;code&gt;develop&lt;/code&gt; is ready for the &amp;#x201C;next release&amp;#x201D; and we have
decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we
branch off and give the release branch a name reflecting the new version
number:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout -b release-1.2 develop
Switched to a new branch "release-1.2"
$ ./bump-version.sh 1.2
Files modified successfully, version bumped to 1.2.
$ git commit -a -m "Bumped version number to 1.2"
[release-1.2 74d9424] Bumped version number to 1.2
1 files changed, 1 insertions(+), 1 deletions(-)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After creating a new branch and switching to it, we bump the version number.
Here,&amp;#xA0;&lt;code&gt;bump-version.sh&lt;/code&gt; is a&amp;#xA0;fictional&amp;#xA0;shell script that changes some files
in the working copy to reflect the new version. (This can of course be a manual
change&amp;#x2014;the point being that &lt;em&gt;some&lt;/em&gt; files change.) Then, the bumped version
number is committed.&lt;/p&gt;
&lt;p&gt;This new branch may exist there for a while, until the release may be rolled
out definitely. During that time, bug fixes may be applied in this branch
(rather than on the &lt;code&gt;develop&lt;/code&gt; branch). Adding large new features here is
strictly prohibited. They must be merged into &lt;code&gt;develop&lt;/code&gt;, and therefore, wait
for the next big release.&lt;/p&gt;
&lt;h4&gt;Finishing a release branch&lt;/h4&gt;
&lt;p&gt;When the state of the release branch is ready to become a real release, some
actions need to be carried out. First, the release branch is merged into
&lt;code&gt;master&lt;/code&gt; (since every commit on &lt;code&gt;master&lt;/code&gt; is a new release &lt;em&gt;by definition&lt;/em&gt;,
remember). Next, that commit on &lt;code&gt;master&lt;/code&gt; must be tagged for easy future
reference to this historical version. Finally, the changes made on the release
branch need to be merged back into &lt;code&gt;develop&lt;/code&gt;, so that future releases also
contain these bug fixes.&lt;/p&gt;
&lt;p&gt;The first two steps in Git:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout master
Switched to branch 'master'
$ git merge --no-ff release-1.2
Merge made by recursive.
(Summary of changes)
$ git tag -a 1.2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The release is now done, and tagged for future reference.&lt;br&gt;
&lt;ins&gt;&lt;strong&gt;Edit:&lt;/strong&gt; You might as well want to use the &lt;code&gt;-s&lt;/code&gt; or &lt;code&gt;-u &amp;lt;key&amp;gt;&lt;/code&gt; flags to sign
your tag cryptographically.&lt;/ins&gt;&lt;/p&gt;
&lt;p&gt;To keep the changes made in the release branch, we need to merge those back
into &lt;code&gt;develop&lt;/code&gt;, though. In Git:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout develop
Switched to branch 'develop'
$ git merge --no-ff release-1.2
Merge made by recursive.
(Summary of changes)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This step may well lead to a merge conflict (probably even, since we have
changed the version number). If so, fix it and commit.&lt;/p&gt;
&lt;p&gt;Now we are really done and the release branch may be removed, since we don&amp;#x2019;t
need it anymore:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git branch -d release-1.2
Deleted branch release-1.2 (was ff452fe).
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Hotfix branches&lt;/h3&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2010/01/hotfix-branches1.png" class="right" alt=""&gt;&lt;/p&gt;
&lt;p&gt;May branch off from:&amp;#xA0;&lt;code&gt;master&lt;/code&gt;&lt;br&gt;
Must merge back into:&amp;#xA0;&lt;code&gt;develop&lt;/code&gt; and &lt;code&gt;master&lt;/code&gt;&lt;br&gt;
Branch naming convention: &lt;code&gt;hotfix-*&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Hotfix branches are very much like release branches in that they are also meant
to prepare for a new production release, albeit unplanned. They arise from the
necessity to act immediately upon an undesired state of a live production
version. When a critical bug in a production version must be resolved
immediately, a hotfix branch may be branched off from the corresponding tag on
the master branch that marks the production version.&lt;/p&gt;
&lt;p&gt;The essence is that work of team members (on the &lt;code&gt;develop&lt;/code&gt; branch) can
continue, while another person is preparing a quick production fix.&lt;/p&gt;
&lt;h4&gt;Creating the hotfix branch&lt;/h4&gt;
&lt;p&gt;Hotfix branches are created from the&amp;#xA0;&lt;code&gt;master&lt;/code&gt; branch. For example, say
version 1.2 is the current production release running live and causing troubles
due to a severe bug. But changes on &lt;code&gt;develop&lt;/code&gt; are yet unstable.&amp;#xA0;We may then
branch off a hotfix branch and start fixing the problem:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout -b hotfix-1.2.1 master
Switched to a new branch "hotfix-1.2.1"
$ ./bump-version.sh 1.2.1
Files modified successfully, version bumped to 1.2.1.
$ git commit -a -m "Bumped version number to 1.2.1"
[hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
1 files changed, 1 insertions(+), 1 deletions(-)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Don&amp;#x2019;t forget to bump the version number after branching off!&lt;/p&gt;
&lt;p&gt;Then, fix the bug and commit the fix in one or more separate commits.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git commit -m "Fixed severe production problem"
[hotfix-1.2.1 abbe5d6] Fixed severe production problem
5 files changed, 32 insertions(+), 17 deletions(-)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Finishing a hotfix branch&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When finished, the bugfix needs to be merged back into &lt;code&gt;master&lt;/code&gt;, but also needs
to be merged back into &lt;code&gt;develop&lt;/code&gt;, in order to&amp;#xA0;safeguard&amp;#xA0;that the bugfix is
included in the next release as well. This is completely similar to how release
branches are finished.&lt;/p&gt;
&lt;p&gt;First, update &lt;code&gt;master&lt;/code&gt; and tag the release.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout master
Switched to branch 'master'
$ git merge --no-ff hotfix-1.2.1
Merge made by recursive.
(Summary of changes)
$ git tag -a 1.2.1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;ins&gt;&lt;strong&gt;Edit:&lt;/strong&gt; You might as well want to use the &lt;code&gt;-s&lt;/code&gt; or &lt;code&gt;-u &amp;lt;key&amp;gt;&lt;/code&gt; flags to sign
your tag cryptographically.&lt;/ins&gt;&lt;/p&gt;
&lt;p&gt;Next,&amp;#xA0;include the bugfix in &lt;code&gt;develop&lt;/code&gt;, too:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git checkout develop
Switched to branch 'develop'
$ git merge --no-ff hotfix-1.2.1
Merge made by recursive.
(Summary of changes)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The one exception to the rule here is that,&amp;#xA0;&lt;strong&gt;when a release branch currently
exists, the hotfix changes need to be merged into that release branch, instead
of &lt;code&gt;develop&lt;/code&gt;&lt;/strong&gt;. Back-merging the bugfix into the release branch will
eventually result in the bugfix being merged into &lt;code&gt;develop&lt;/code&gt; too, when the
release branch is finished. (If work in &lt;code&gt;develop&lt;/code&gt; immediately requires this
bugfix and cannot wait for the release branch to be finished, you may safely
merge the bugfix into &lt;code&gt;develop&lt;/code&gt; now already as well.)&lt;/p&gt;
&lt;p&gt;Finally, remove the temporary branch:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-console"&gt;
$ git branch -d hotfix-1.2.1
Deleted branch hotfix-1.2.1 (was abbe5d6).
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;While there is nothing really shocking new to this branching model, the &amp;#x201C;big
picture&amp;#x201D; figure that this post began with has turned out to be tremendously
useful in our projects. It forms an elegant mental model that is easy to
comprehend and allows team members to develop a shared understanding of the
branching and releasing processes.&lt;/p&gt;
&lt;p&gt;A high-quality &lt;span class="caps"&gt;PDF&lt;/span&gt; version of the figure is provided here. Go ahead and hang it
on the wall for quick reference at any time.&lt;/p&gt;
&lt;p&gt;&lt;ins&gt;&lt;strong&gt;Update:&lt;/strong&gt; And for anyone who requested it: here&amp;#x2019;s the
&lt;a href="http://github.com/downloads/nvie/gitflow/Git-branching-model-src.key.zip"&gt;gitflow-model.src.key&lt;/a&gt;
of the main diagram image (Apple Keynote).&lt;/ins&gt;&lt;/p&gt;
&lt;p style="text-align:center;"&gt;&lt;a href="http://github.com/downloads/nvie/gitflow/Git-branching-model.pdf"&gt;&lt;img src="http://nvie.com/img/pdf.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="http://github.com/downloads/nvie/gitflow/Git-branching-model.pdf"&gt;Git-branching-model.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Feel free to add your comments!&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;In this post I present the development model that I&amp;#8217;ve introduced for all of my
projects (both at work and private) about a year ago, and which has turned out
to be very successful. I&amp;#8217;ve been meaning to write about it for a while now, but
I&amp;#8217;ve never really found the time to do so thoroughly, until now. I won&amp;#8217;t talk
about any of the projects&amp;#8217; details, merely about the branching strategy and
release management.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2009-09-19:/posts/auto-generate-classes-for-your-core-data-data-model-revisited/</id>
    <title type="html">Auto-generate classes for your Core Data data model, revisited</title>
    <published>2009-09-18T22:00:00Z</published>
    <updated>2009-09-18T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/auto-generate-classes-for-your-core-data-data-model-revisited/" />
    <content type="html">&lt;p&gt;A few months ago, I wrote about &lt;a href="http://nvie.com/archives/263"&gt;automatically generating classes for your Core
Data entities&lt;/a&gt; and how to automate Xcode using users scripts,
such that, when your model changed, you only needed to run your custom script
again and your intermediate model files would reflect the new situation.&lt;/p&gt;
&lt;p&gt;Well, the guys from the &lt;a href="http://github.com/rentzsch/mogenerator"&gt;mogenerator&lt;/a&gt;
project have come up with a far superior solution in the mean time. The newest
version of mogenerator comes with an Xcode plugin named Xmo&amp;#x2019;d, which monitors
your &lt;code&gt;*.xcdatamodel&lt;/code&gt; file for changes and, as soon as it changes, regenerates
all of the neccessary files.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This means that there is officially no more reason not to use mogenerator.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To set it up, download the installer package from their (improved) &lt;a href="http://rentzsch.github.com/mogenerator/"&gt;project
website&lt;/a&gt; and install it. (Before
installing, please read the important release note about the renamed method
&lt;code&gt;+newInManagedObjectContext:&lt;/code&gt;.)&lt;/p&gt;
&lt;p&gt;When installed, all you need to do is Command-click your &lt;code&gt;*.xcdatamodel&lt;/code&gt; file,
click Get Info, switch to the Comments tab and add the string &amp;#x201C;xmod&amp;#x201D; to the
comment field. This is the trigger for Xmo&amp;#x2019;d to start (re)generating your
machine-classes (the underscored class files) when the data model changes.
Brilliant!&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/10/comment-field.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Oh, the default location at which the generated files will be emitted, is in a
folder named after your project, right next to where your &lt;code&gt;*.xcdatamodel&lt;/code&gt;
already sits:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/10/emission-location.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Enjoy it and spread the word!&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;A few months ago, I wrote about &lt;a href="/archives/263"&gt;automatically generating classes for your Core
Data entities&lt;/a&gt; and how to automate Xcode using users scripts,
such that, when your model changed, you only needed to run your custom script
again and your intermediate model files would reflect the new situation.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2009-06-30:/posts/automatically-generate-classes-for-your-core-data-data-model/</id>
    <title type="html">Automatically generate classes for your Core Data data model</title>
    <published>2009-06-29T22:00:00Z</published>
    <updated>2009-06-29T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/automatically-generate-classes-for-your-core-data-data-model/" />
    <content type="html">&lt;p&gt;When designing a Core Data data model for your Xcode projects, you can choose to create Objective-C object wrappers for your entities, so that you can profit from type-safe code. The normal, tedious, workflow for this is that you select each entity from the model designer, select all of its attributes and relationships, Ctrl-click it and from the contextual menu first select &amp;#x201C;Copy Obj-C 2.0 Method Declarations To Clipboard&amp;#x201D;, paste it into the appropriate class header file, then do the same thing for the method implementations in the class implementation file. Waaaaaay too much work. Not to mention the manual copy-pastes are really hard to keep in sync once you start adding functionality to these class files, since you don&amp;#x2019;t want to overwrite those additions, but you want to keep replacing everything else.&lt;/p&gt;
&lt;h3&gt;Meet mogenerator&lt;/h3&gt;
&lt;p&gt;Fortunately, there is a great way for automating this process, using
mogenerator. The tool can be downloaded as a &lt;a href="http://aralbalkan.com/2152"&gt;&lt;span class="caps"&gt;DMG&lt;/span&gt;
installer&lt;/a&gt; (Aral Balkan&amp;#x2019;s blog mentions a workaround
for older Xcode versions, but for Xcode 3.1.3 it worked out of the box for me),
or you can checkout the sources from
&lt;a href="http://github.com/rentzsch/mogenerator/"&gt;github&lt;/a&gt; and build it yourself.&lt;/p&gt;
&lt;p&gt;The mogenerator command line tool eases this generation process by reading the
&lt;code&gt;*.xcdatamodel&lt;/code&gt; file and generating both class files and intermediate class files
for each entity. The intermediate classes (called &lt;em&gt;machine&lt;/em&gt; classes) are
continuously overwritten by subsequent regenerations, so you should never edit
the contents of these files. The actual model object classes (called &lt;em&gt;human&lt;/em&gt;
classes) inherit from those intermediate classes with a default empty
implementation, allowing for all manual extensions.&lt;/p&gt;
&lt;p&gt;For example, when you design a model with two entities Foo and Bar, mogenerator
can be invokes as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mogenerator -m MyDocument.xcdatamodel -M Entities -H Model&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The flag &lt;code&gt;-m&lt;/code&gt; sets the input model file, while &lt;code&gt;-M&lt;/code&gt; and &lt;code&gt;-H&lt;/code&gt; specify the output
directories where the machine and human classes should be generated
respectively.&lt;/p&gt;
&lt;p&gt;This does a few things:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;In the Entities subdirectory, there will be generated header and
  implementation files for NSManagedObject subclasses called _Foo and _Bar;&lt;/li&gt;
	&lt;li&gt;In the Model subdirectory, there will be generated classes called Foo and
  Bar&amp;#x2014;respective subclasses of _Foo and _Bar. These are only created if not
  available yet. Otherwise, they are left as is.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Wrapping it up&lt;/h3&gt;
&lt;p&gt;The trick of how mogenerator works is that you can run the script as often as
you want. After every change in your model, you&amp;#x2019;ll want to re-run the
generation again to update the machine classes. You could easily leave Xcode,
switch over to Terminal and issue the command above. But you&amp;#x2019;ll get quite tired
of that after a few times.&lt;/p&gt;
&lt;p&gt;Therefore, I&amp;#x2019;ve written a custom user script that can be added to Xcode (see
figure), which does the following:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;You can configure the output directories in the first lines of the script.
  There is no per-project configuration, so choose them as you would like to
  use them with all your projects;&lt;/li&gt;
	&lt;li&gt;Mind that these generated files are not automatically included in your Xcode
  project. Drag them there once and ideally put the machine generated classes
  into a group under &amp;#x201C;Other resource&amp;#x201D;, so you never have to see them again.
  Whenever you add a new class to your model, new files will be generated, so
  again you must drag the new files to reference those, of course!&lt;/li&gt;
	&lt;li&gt;The script can be run with any file in the project opened. It starts out with
  that file and walks up the directory tree to search for your Xcode project.
  If found, it executes all the rest from your project directory. (Suggestions
  are welcome, I could not find a better implementation since a variable like
  &lt;code&gt;%%%{PBXProjectPath}%%%&lt;/code&gt; does not seem to exist.)&lt;/li&gt;
	&lt;li&gt;It invokes mogenerator to generate all model classes for the project. It is
  smart enough to detect whether you are using Brian Webster&amp;#x2019;s
  &lt;a href="http://www.fatcatsoftware.com/blog/2008/per-object-ordered-relationships-using-core-data"&gt;BWOrderedManagedObject&lt;/a&gt;
  in your project. If so, your generated machine classes will inherit from
  BWOrderedManagedObject instead of NSManagedObject.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/07/set-user-script.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;p&gt;To add this script to Xcode, open the menu Scripts (the icon) &amp;gt; Edit User
Scripts&amp;#x2026; Click the &amp;#x201C;+&amp;#x201D;-button on the bottom-left and select &amp;#x201C;New shell
script&amp;#x201D;.  Set the values for Input, Directory, Output and Errors as in the
screenshot above, then copy-paste the script below into the code window. Add a
nice keyboard shortcut to this action to top it off :-) I&amp;#x2019;ve chosen ^&amp;#x2325;&amp;#x2318;G for
this.&lt;/p&gt;
&lt;p&gt;Please feel free to leave any comments if this helped you.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-sh"&gt;
#!/bin/sh
#
# Automatic (re)generation of model classes for all *.xcdatamodel files.
# Written by Vincent Driessen
#
# You are free to use this script in any way.
# The original blog post is http://nvie.com/archives/263
#

# Define output directories
MACHINE_DIR="Entities"
MODEL_DIR="Model"

# Look for the Xcode project directory for this file
cd `dirname "%%%{PBXFilePath}%%%"`
while [ `ls -d *.xcodeproj 2&amp;amp;gt;/dev/null | wc -l` -eq 0 ]; do
    cd ..
    if [ "`pwd`" = "/" ]; then
        echo "No Xcode project found."
        exit 1
    fi
done

echo "Project directory is `pwd`"

#
# Check to see whether the base class is just a default (NSManagedObject) or
# maybe Brian Webster's excellent BWOrderedManagedObject.
# http://fatcatsoftware.com/blog/2008/per-object-ordered-relationships-using-core-data
#
# NOTE:
# The check really is quite arbitrary: if there exists a file called
# BWOrderedManagedObject.h somewhere below the project root directory, we
# assume that we want to use this as the base class for all generated classes.
#
EXTRA_FLAGS=
if [ `find . -name BWOrderedManagedObject.h | wc -l` -gt 0 ]; then
	EXTRA_FLAGS+="--base-class BWOrderedManagedObject"
fi

# Generate the model classes using mogenerator
for model in `find . -name '*.xcdatamodel'`; do
   # The output directories have to exist, so create them
   mkdir -p "${MACHINE_DIR}" "${MODEL_DIR}"
   mogenerator ${EXTRA_FLAGS} -m "${model}" -M "${MACHINE_DIR}" -H "${MODEL_DIR}"
done
&lt;/code&gt;&lt;/pre&gt;</content>
    <summary type="html">&lt;p&gt;When designing a Core Data data model for your Xcode projects, you can choose to create Objective-C object wrappers for your entities, so that you can profit from type-safe code. The normal, tedious, workflow for this is that you select each entity from the model designer, select all of its attributes and relationships, Ctrl-click it and from the contextual menu first select &amp;#8220;Copy Obj-C 2.0 Method Declarations To Clipboard&amp;#8221;, paste it into the appropriate class header file, then do the same thing for the method implementations in the class implementation file. Waaaaaay too much work. Not to mention the manual copy-pastes are really hard to keep in sync once you start adding functionality to these class files, since you don&amp;#8217;t want to overwrite those additions, but you want to keep replacing everything else.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2009-06-22:/posts/nsmanagedobjectcontext-extensions/</id>
    <title type="html">NSManagedObjectContext extensions</title>
    <published>2009-06-21T22:00:00Z</published>
    <updated>2009-06-21T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/nsmanagedobjectcontext-extensions/" />
    <content type="html">&lt;p&gt;The Core Data framework rules, and its &lt;span class="caps"&gt;API&lt;/span&gt; is really really powerful. But
really, why does the Core Data &lt;span class="caps"&gt;API&lt;/span&gt; require us to write so much boilerplate
code? Simple things need to be simple.&lt;/p&gt;
&lt;p&gt;Why is the deletion of a managed object from the NSManagedObjectContext so
easy:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-objc"&gt;
[context deleteObject:someObject];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compared to its creation:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-objc"&gt;
[NSEntityDescription insertNewObjectForEntityForName:@"someObjectClassName"
                              inManagedObjectContext:context];
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Extending NSManagedObjectContext&lt;/h3&gt;
&lt;p&gt;Add the following category on NSManagedObjectContext to all of your Core Data
projects and your pains will be history.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-objc"&gt;
@implementation NSManagedObjectContext(NSManagedObjectContextConvenienceMethods)

- (id)newObject:(Class)entity {
   return [NSEntityDescription insertNewObjectForEntityForName:[entity description]
                                        inManagedObjectContext:self];
}

@end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, a call to create a new object is as easy as deleting it.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-objc"&gt;
[context newObject:[someEntity class]];
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Further enhancements of NSManagedObject&lt;/h3&gt;
&lt;p&gt;Matt Gallagher has written an
&lt;a href="http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html"&gt;excellent article&lt;/a&gt;
about how to further enhance NSManagedObject for adding simple, one-line fetch
support. Be sure to check it out.&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;The Core Data framework rules, and its &lt;span class="caps"&gt;API&lt;/span&gt; is really really powerful. But
really, why does the Core Data &lt;span class="caps"&gt;API&lt;/span&gt; require us to write so much boilerplate
code? Simple things need to be simple.&lt;/p&gt;</summary>
  </entry>
  <entry>
    <id>tag:nvie.com,2009-06-20:/posts/nspredicateeditor-tutorial/</id>
    <title type="html">NSPredicateEditor tutorial</title>
    <published>2009-06-19T22:00:00Z</published>
    <updated>2009-06-19T22:00:00Z</updated>
    <link rel="alternate" href="http://nvie.com/posts/nspredicateeditor-tutorial/" />
    <content type="html">&lt;p&gt;Cocoa offers a nice visual editor for editing NSPredicate objects templates,
called NSPredicateEditor. The NSPredicateEditor can be set up using code or in
Interface Builder, which is preferable for simple use. The setup is fairly easy
once you know how to do it. In this tutorial, we&amp;#x2019;ll be building a simple
predicate editor example which shows the basic functionality of the predicate
editor.&lt;/p&gt;
&lt;h3&gt;Setting up the AppDelegate&lt;/h3&gt;
&lt;p&gt;Begin by creating a new Xcode project (Cmd+Shift+N). Name your project wisely
and create a new class in the Classes group, called AppDelegate.&lt;/p&gt;
&lt;p&gt;Switch to the header file and declare two IBOutlets for the main window and the
sheet on which we&amp;#x2019;re going to display the editor in a few minutes. Also, add
two IBActions called &lt;code&gt;-openEditor:&lt;/code&gt; and &lt;code&gt;-closeEditor:&lt;/code&gt;. Finally, add an ivar
that holds the NSPredicate we&amp;#x2019;re going to be editing.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/07/appdelegate1.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Next, we&amp;#x2019;re going to fire up Interface Builder to build the UI. Double click on
the MainMenu.xib file under the Resources group.&lt;/p&gt;
&lt;p&gt;Drag an NSObject object from the Library into the &lt;span class="caps"&gt;XIB&lt;/span&gt; and call it App Delegate.
Hit Cmd+6 and make it a subclass of the AppDelegate class we just created.
Then, hook it up to the delegate property of the File&amp;#x2019;s Owner.&lt;/p&gt;
&lt;p class="autoalign"&gt;&lt;img src="http://nvie.com/img/2009/07/hookup-appdelegate.png" alt=""&gt;
&lt;img src="http://nvie.com/img/2009/07/choose-delegate.png" alt=""&gt;&lt;/p&gt;
&lt;p class="clear"&gt;Drag a new NSWindow to the &lt;span class="caps"&gt;XIB&lt;/span&gt;-file and call it Sheet. Make sure the
checkbox &amp;#x201C;Visible At Launch&amp;#x201D; is deselected or the sheet will not display
properly at runtime. Open the main window and add a NSButton and a NSTextView
to it. To the sheet window, drag a NSPredicateEditor and a NSButton. They
should look somewhat like this now:&lt;/p&gt;
&lt;p class="autoalign"&gt;&lt;img src="http://nvie.com/img/2009/07/Picture-5.png" alt=""&gt;
&lt;img src="http://nvie.com/img/2009/07/Picture-4.png" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Now, we can hook up the outlets and actions as usual. Hook up the Edit
Predicate button on the main window to &lt;code&gt;-openEditor:&lt;/code&gt; and the OK button on the
sheet window to closeEditor:. Then hook up the mainWindow and sheet outlets of
the AppDelegate class to the respective NSWindow objects.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/07/hookup-windows.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;h3&gt;Configure the NSPredicateEditor&lt;/h3&gt;
&lt;p&gt;Once we have all of the connections between Xcode and Interface Builder set up,
we can continue to configure the predicate editor itself, which is actually
what this tutorial is all about. An NSPredicateEditor control uses a list of
NSPredicateEditorRowTemplate objects that can handle individual (simple)
NSPredicate objects. Combining these row templates enables the
NSPredicateEditor to edit compound predicates. There is no limitation to the
depth of nested compound predicates, although nesting too deep would not be
advisable from a usability perspective.&lt;/p&gt;
&lt;p&gt;In the edit window, click a few times until the &amp;#x201C;name contains&amp;#x201D; row template is
selected. In this row template, you define which key paths are supported.
Supported here means two things:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
&lt;strong&gt;matching&lt;/strong&gt;&amp;#x2014;given an existing predicate with this key path in it on the
  left-hand side, this row template can be used to alter the predicate;&lt;/li&gt;
	&lt;li&gt;
&lt;strong&gt;generation&lt;/strong&gt;&amp;#x2014;when using the editor to create new predicates, adding a new
  rule for this key path will generate a predicate for this key path.&lt;/li&gt;
&lt;/ul&gt;
&lt;p class="autoalign"&gt;&lt;img src="http://nvie.com/img/2009/07/Picture-10.png" alt=""&gt;
&lt;img src="http://nvie.com/img/2009/07/Picture-13.png" alt=""&gt;&lt;/p&gt;
&lt;h4&gt;Gotcha&lt;/h4&gt;
&lt;p&gt;A small gotcha, at least one that initially put me on the wrong foot, is that
there is quite a difference between the rows that you see design-time in
Interface Builder and the rows that are available run-time. At design-time, you
define the NSPredicateEditorRowTemplate objects while at run-time you see
instances of them. Hence, the number of rows at design-time is the &lt;em&gt;number of
different row templates available&lt;/em&gt;. At run-time, however, the number of rows is
the number of &lt;em&gt;(simple) predicates within the compound predicate&lt;/em&gt; (which each
has an associated row template instance that handles it). Subtle difference.&lt;/p&gt;
&lt;p&gt;In short, in Interface Builder, &lt;strong&gt;create a row template for &lt;em&gt;each type of match&lt;/em&gt;
that you want to allow&lt;/strong&gt;. Typically, this means for each data type that you want
to support. In our example, we have the following setup:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Row template #1 is for all string matches. Here, we have defined it for the
  key paths &amp;#x201C;firstname&amp;#x201D;, &amp;#x201C;lastname&amp;#x201D;, &amp;#x201C;address.street&amp;#x201D; and &amp;#x201C;address.city&amp;#x201D;. They,
  per definition, have the same  allowed operators. If we want to have an other
  set of operators for a specific key path, we need to define a separate row
  template for it.&lt;/li&gt;
	&lt;li&gt;Row template #2 is for date matches, i.e. our &amp;#x201C;birthdate&amp;#x201D; key path.&lt;/li&gt;
	&lt;li&gt;Row template #3 is for all integer matches, i.e. our &amp;#x201C;address.number&amp;#x201D; key
  path.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The result looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/07/row-templates-setup.png" class="center" alt=""&gt;&lt;/p&gt;
&lt;h3&gt;Using bindings to connect the predicate to the UI&lt;/h3&gt;
&lt;p&gt;&lt;img src="http://nvie.com/img/2009/07/bindings.png" class="right" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Next up, we simply connect both the text view from the main window and the
predicate editor from the sheet window to the predicate key path using Cocoa
bindings. In order to do so, select the NSPredicateEditor (first click the
control to select the scroll view, then click again to select the inner
NSPredicateEditor), hit Cmd+4. Then, unfold the &amp;#x201C;Value&amp;#x201D; binding and hook it up
to the App Delegate&amp;#x2019;s &amp;#x201C;predicate&amp;#x201D; key path.&lt;/p&gt;
&lt;p&gt;Do the same for the text view in the main window, but this time hook it up to
the &amp;#x201C;predicate.description&amp;#x201D; key path (since only strings can be displayed in a
text view). When you do this, make sure that the text view is read-only, since
the description property of objects should never be set.&lt;/p&gt;
&lt;h3&gt;Writing the code to wrap it all up&lt;/h3&gt;
&lt;p&gt;Finally, we have only a bit of code to write in our AppDelegate implementation,
so let&amp;#x2019;s go:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-objc"&gt;//
//  AppDelegate.m
//  PredicateEditorTest
//
//  Created by Vincent on 20-07-09.
//

#import "AppDelegate.h"

#define DEFAULT_PREDICATE @"(firstname = 'John' AND lastname = 'Doe') " \
                    @"OR birthdate &amp;amp;gt; CAST('01/01/1985', 'NSDate') " \
                    @"OR address.city = 'Chicago' " \
                    @"AND address.street != 'Main Street' " \
                    @"OR address.number &amp;amp;gt; 1000"

@implementation AppDelegate

- (id)init
{
   self = [super init];
   if (self != nil) {
      predicate = [[NSPredicate predicateWithFormat:DEFAULT_PREDICATE] retain];
   }
   return self;
}

- (void)dealloc
{
   [predicate release];
   [super dealloc];
}

- (IBAction)openEditor:(id)sender
{
   [NSApp beginSheet:sheet
      modalForWindow:mainWindow
      modalDelegate:nil
      didEndSelector:NULL
        contextInfo:nil];
}

- (IBAction)closeEditor:(id)sender
{
   [NSApp endSheet:sheet];
   [sheet orderOut:sender];
}

@end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the &lt;code&gt;-init:&lt;/code&gt; method, we initialize the AppDelegate by setting and retaining
a reference to a rather complex default predicate. When the &lt;span class="caps"&gt;XIB&lt;/span&gt; is loaded at
run-time, the textbox shows exactly this predicate and it can be edited by
invoking the edit sheet.&lt;/p&gt;
&lt;p&gt;The actual implementation of the &lt;code&gt;-openEditor:&lt;/code&gt; and &lt;code&gt;-closeEditor:&lt;/code&gt; methods
aren&amp;#x2019;t too exciting.&lt;/p&gt;
&lt;h3&gt;Downloading the source&lt;/h3&gt;
&lt;p&gt;You can download the source code for this tutorial as an Xcode project here.&lt;/p&gt;
&lt;p style="text-align:center;"&gt;&lt;a href="http://nvie.com/files/PredicateEditorTest.zip"&gt;&lt;img src="http://nvie.com/img/zip.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="http://nvie.com/files/PredicateEditorTest.zip"&gt;PredicateEditorTest.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Have a blast!&lt;/p&gt;</content>
    <summary type="html">&lt;p&gt;Cocoa offers a nice visual editor for editing NSPredicate objects templates,
called NSPredicateEditor. The NSPredicateEditor can be set up using code or in
Interface Builder, which is preferable for simple use. The setup is fairly easy
once you know how to do it. In this tutorial, we&amp;#8217;ll be building a simple
predicate editor example which shows the basic functionality of the predicate
editor.&lt;/p&gt;</summary>
  </entry>
</feed>

