When first introducing Markdown support in Carmine Contraption I reached for what was familiar. In this case that was the perl script written by John Gruber. To use this script from Carmine Contraption I had to wrap a system call in a method.

def self.translate_markdown content
  `echo "#{content}" | bin/markdown.pl`
end

Sure, this implementation worked, but there were many problems. It was slow, ugly, and bloated the size of the git repository. All of those reasons provided pain, but not enough to take time to fix it. After all, it still was able to produce the formatted content. At least until I upgraded the version of Ubuntu running on my VPS. After a few hours of debugging I found that my path was unknowingly modified. Long story short, I finally found enough motivation to remove the code smell.

Turns out that there is an excelent Markdown parsing library for Ruby. Even GitHub uses it. Ten minutes after finding Redcarpet my code was transformed to this.

require 'redcarpet'

def translate_markdown content
    md = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
    md.render(content)
end

The main issue here is explicit vs implicit dependencies. The original version of this method had two implicit dependencies: correct version of perl and correct path variable. The new version has one explicit dependency: Redcarpet. The implicit dependencies are ninjas, lurking in the shadows waiting to pounce at the most inopportune time. Where as the explicit dependencies can be controlled easily by modifying the Gemfile.