<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>My name is Mitchell Hashimoto. I’m passionate about open source software, DevOps, and programming languages (with a focus on functional programming).</description><title>Mitchell Hashimoto</title><generator>Tumblr (3.0; @mitchellhashimoto)</generator><link>http://mitchellhashimoto.com/</link><item><title>"New" Purely Functional Data Structures</title><description>&lt;a href="http://cstheory.stackexchange.com/questions/1539/whats-new-in-purely-functional-data-structures-since-okasaki/1550"&gt;"New" Purely Functional Data Structures&lt;/a&gt;: &lt;p&gt;This StackOverflow post covers “new” purely functional data structures created since &lt;a href="http://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki/dp/0521663504"&gt;Okasaki’s book “Purely Functional Data Structures”&lt;/a&gt; published in 1998.&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/8871026043</link><guid>http://mitchellhashimoto.com/post/8871026043</guid><pubDate>Sat, 13 Aug 2011 10:38:28 -0700</pubDate></item><item><title>"The Essence of Functional Programming" Part 1: The Identity Monad</title><description>&lt;p&gt;This is the first of a new series of posts that will take papers that I read and will explain them and attempt to make them more concrete (and less theoretical) by showing real world examples using more industry-standard languages. These papers will be tagged with &lt;a href="http://mitchellhashimoto.com/tagged/theory-in-practice"&gt;theory-in-practice&lt;/a&gt;. For more information on the “Theory in Practice” series, read the &lt;a href="http://mitchellhashimoto.com/post/7080543745/theory-in-practice"&gt;introductory post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today’s paper is &lt;a href="http://homepages.inf.ed.ac.uk/wadler/topics/monads.html#essence"&gt;“The essence of functional programming”&lt;/a&gt; by Philip Wadler. This paper is widely known as the paper which popularized monads, and introduces them in a relatively elementary context with a focus on practical programming use.&lt;/p&gt;

&lt;p&gt;This is part 1 of a multi-part series. In order to allow the information to soak in and to not consume too much of your time, I’ve decided to split this into multiple parts which I will publish over the coming weeks. These will all be tagged with &lt;a href="http://mitchellhashimoto.com/tagged/essence-of-functional-programming"&gt;essence-of-functional-programming&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Part 1 will cover the inspiration for monads as well as introduce the trivial monad.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prior knowledge required:&lt;/strong&gt; Basic programming experience with basic experience in functional programming (in any language, whether it be Ruby, Python, C, etc.). The examples will be given in Haskell and Scala.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h1&gt;Inspiration: Purity vs. Impurity&lt;/h1&gt;

&lt;p&gt;The inspiration for monads comes from the desire to program in a purely functional environment, but to ease program modification in cases where it appears impure languages have the upper hand.&lt;/p&gt;

&lt;h3&gt;What is “purity?” What is “impurity?”&lt;/h3&gt;

&lt;p&gt;While a conceptual “pure vs. impure” discussion is out of the scope of this post and the definition of purity was not covered in the paper, I’ll quickly define the terms. A function is &lt;strong&gt;pure&lt;/strong&gt; if it generates it’s result using nothing but the parameters given to it, whereas a function is &lt;strong&gt;impure&lt;/strong&gt; if it uses or modifies some outside state. A quick example of a pure function:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
def add(x: Int, y: Int) = x + y
&lt;/pre&gt;

&lt;p&gt;And that same function becoming impure, since we’re modifying global state by outputting text to the world:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
def add(x: Int, y: Int) = {
  println("Adding!")
  x + y
}
&lt;/pre&gt;

&lt;p&gt;Additionally, the benefits of purity are:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Increased modularity&lt;/strong&gt; - A pure function can be used anywhere and it will be have the same way. Therefore pure functions are ideal for libraries among programs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrency safe&lt;/strong&gt; - Since a pure function modifies no outside state, it can be easily (theoretically) parallelized. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Simplified testing&lt;/strong&gt; - Once you test all input conditions and edge cases, you can be certain the function behaves correctly.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;Of course, there are also benefits to impurity:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;strong&gt;State&lt;/strong&gt; - Its very easy to maintain state in impure situations, since you just add a global variable to the mix, and every function can use it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Quick edits&lt;/strong&gt; - You can just throw in a &lt;code&gt;println&lt;/code&gt; wherever you see fit to assist in debugging.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;A pure pain point&lt;/h3&gt;

&lt;p&gt;As an example for comparing purity vs impurity, let’s use a basic interpreter which takes as input a program, evaluates it, and returns the result. This is surely a simple venture in both pure and impure settings.&lt;/p&gt;

&lt;p&gt;Now, what if we wanted to add error handling to this interpreter? With impurity, we could simply throw exceptions with the error message. But in a pure environment, we would have to modify the result type to also include errors at each recursive point, and each function would have to check for errors prior to running. Holy smokes batman, that’s annoying.&lt;/p&gt;

&lt;p&gt;Okay, what about adding an execution count? With impurity, all that needs to be done is to add a global variable that is incremented with each operation. Again, though, for a pure language, we would have to modify the result type to include execution count everywhere.&lt;/p&gt;

&lt;p&gt;Based on these examples, it looks like impurity wins completely! But, there is another option: &lt;em&gt;Monads&lt;/em&gt;. Wadler argues that monads can be used to structure an interpreter so that the above changes can be made just as easily as with an impure language, while maintaining the purity of the computations.&lt;/p&gt;

&lt;h1&gt;The Monad&lt;/h1&gt;

&lt;p&gt;A monad consists of three parts. In Haskell, it is defined like so:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
class Monad m where
  unitM :: a -&gt; m a
  bindM :: m a -&gt; (a -&gt; m b) -&gt; m b
&lt;/pre&gt;

&lt;p&gt;The rough equivalent in Scala would be the following:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
trait Monad[M[_]] {
  def unitM[A](a: A): M[A]
  def bindM[A, B](a: M[A], f: A =&gt; M[B]): M[B]
}
&lt;/pre&gt;

&lt;p&gt;As you can see:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;strong&gt;M&lt;/strong&gt; is a type constructor. That is, its not a complete type on its own, because it requires another type to complete it. An example, &lt;code&gt;List&lt;/code&gt; in Scala is not a type, but &lt;code&gt;List[Int]&lt;/code&gt; is. Therefore, &lt;code&gt;List&lt;/code&gt; is a kind of type constructor.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;unitM&lt;/strong&gt; is a function which takes a value and “lifts” it into the monad. So if you had a just an int, such as &lt;code&gt;7&lt;/code&gt;, and your monad was a list of ints, then &lt;code&gt;unitM&lt;/code&gt; would make it a list &lt;code&gt;[7]&lt;/code&gt;. In fact, although we won’t talk about it in this post, &lt;code&gt;List&lt;/code&gt; is a monad!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;bindM&lt;/strong&gt;  is a function which allows computations to be done on the value held by the monad. Building on the list example, if you wanted to double each item in the list, you could do &lt;code&gt;bindM([7], (x: Int =&gt; x + x))&lt;/code&gt; and this would return &lt;code&gt;[14]&lt;/code&gt;. Notice the computation was done on the items inside, but the result was still contained in the monad type, which was &lt;code&gt;List&lt;/code&gt; for our short examples here.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;So, &lt;code&gt;unitM&lt;/code&gt; can be thought of as bringing a value &lt;em&gt;into&lt;/em&gt; a monad and &lt;code&gt;bindM&lt;/code&gt; can be thought of taking that value, doing some computation, and putting it back into a monad. The question remains: how do I get a value out of a monad? This operation is typically specific to each monad, so it is not generalized. You’ll see examples later.&lt;/p&gt;

&lt;p&gt;Okay, I realize this was &lt;em&gt;really&lt;/em&gt; abstract. The main takeaway from this section is that a Monad is nothing more than the three parts above. Don’t worry about understanding the “why?” of monads yet, concrete examples are on the way!&lt;/p&gt;

&lt;h2&gt;A basic interpreter&lt;/h2&gt;

&lt;p&gt;Our concrete example is going to be a basic interpreter. The interpreter was originally written in Haskell in Wadler’s paper. I’ve converted this to Scala. Both sources are &lt;a href="https://gist.github.com/1079807"&gt;available in this gist&lt;/a&gt;. Please read the interpreter over until you understand what it should do. You don’t need to understand the monadic parts, of course, but you should be able to get the gist of what it does. As an example, take the following input into the interpreter:&lt;/p&gt;

&lt;pre class="prettyprint lang-scala"&gt;
term = App(Lam("x", Add(Var("x"), Var("x"))), 
           Add(Con(10), Con(11)))
&lt;/pre&gt;

&lt;p&gt;The above is roughly equivalent to the following Scala code:&lt;/p&gt;

&lt;pre class="prettyprint lang-scala"&gt;
term = ((x: Int) =&gt; x + x)(10 + 11)
&lt;/pre&gt;

&lt;p&gt;With that input, running the interpreter should yield &lt;code&gt;42&lt;/code&gt;, since it adds 10 and 11, to make 21, and that is passed as the parameter into the lambda function, which doubles it to 42.&lt;/p&gt;

&lt;p&gt;We will take the above interpreter, extend it in various ways using monads, and compare this approach to what would be necessary in an impure language.&lt;/p&gt;

&lt;h3&gt;Variation zero: Standard Interpreter with the Identity Monad&lt;/h3&gt;

&lt;p&gt;To begin, let’s create the trivial monad. This monad doesn’t actually &lt;em&gt;do&lt;/em&gt; anything, it just wraps the value, but its a gentle introduction to monads and their operations:&lt;/p&gt;

&lt;pre class="prettyprint"&gt;
case class Id[+A](val value: A)

object IdOps extends Monad[Id] {
  def unitM[A](a: A) = Id(a)
  def bindM[A,B](a: Id[A], f: A =&gt; Id[B]) = f(a.value)
  def showM[A](a: Id[A]) = a.value.toString
}
&lt;/pre&gt;

&lt;p&gt;This monad is called the “identity monad.” It is called this because it doesn’t serve any real purpose except to wrap a value. While it may not be necessary, I will explain each operation for the purpose of being explicit about each monad operation:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;The type constructor &lt;strong&gt;M&lt;/strong&gt; in this case is &lt;strong&gt;Id&lt;/strong&gt;. As you can see, this matches the above definition of a monad by taking a single value of some type.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;unitM&lt;/strong&gt; takes a value and wraps it in &lt;code&gt;Id&lt;/code&gt;. This brings the value into the monad, just as was described earlier.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;bindM&lt;/strong&gt; allows computations to be done on the value of the monad. In this case, the function is applied directly to the value. Since this is the identity monad, there is nothing sneaky going on here, just simple function application. If we had an &lt;code&gt;Id(7)&lt;/code&gt; and did &lt;code&gt;bindM(Id(7), (x: Int =&gt; unitM(x * 2)))&lt;/code&gt; then the result would be &lt;code&gt;Id(14)&lt;/code&gt;. Note the symmetry between this and the example given earlier when defining monads.&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;For the purpose of our interpreter, we’ve also introduced a &lt;strong&gt;showM&lt;/strong&gt; function. This is not a standard monad function in general, but we’re requiring all monads implement this so that we have a way to get the value out of the monad as a string.&lt;/p&gt;

&lt;p&gt;Despite its practical uselessness, the identity monad serves a practical purpose for this post since it demonstrates the simplest monad. The result of using this monad with our example is that it constructs a basic, working, interpreter.&lt;/p&gt;

&lt;h2&gt;Testing the Monad&lt;/h2&gt;

&lt;p&gt;In order to test the monads we’ll be using during this series, I’ve constructed the interpreter example in such a way that you simply have to subclass the &lt;code&gt;Interpreter&lt;/code&gt; trait and point it to our latest monad to see the changes. Add the identity monad and create the interpreter:&lt;/p&gt;

&lt;pre class="prettyprint lang-scala"&gt;
class StandardInterp extends Interpreter {
  type M[A] = Id[A]
  override val monadOps = IdOps
}
&lt;/pre&gt;

&lt;p&gt;Then create a basic test program and run it:&lt;/p&gt;

&lt;pre class="prettyprint lang-scala"&gt;
val current = new StandardInterp()
import current._

val term: Term = App(Lam("x", Add(Var("x"), Var("x"))),
                     Add(Con(10), Con(11)))

println(current.test(term))
&lt;/pre&gt;

&lt;p&gt;The result should be “42.”&lt;/p&gt;

&lt;p&gt;This is what we expected, since our monad does nothing in this case except introduces us to the basic operations and usage of it. It should be clear to see that in the future we’ll add considerably more logic to the monad, and the interpreter will quite simply be augmented with additional functionality without at all compromising the purity of it’s functions.&lt;/p&gt;

&lt;p&gt;Look for part 2 in the coming days!&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/7564789784</link><guid>http://mitchellhashimoto.com/post/7564789784</guid><pubDate>Tue, 12 Jul 2011 23:06:00 -0700</pubDate><category>functional-programming</category><category>haskell</category><category>monad</category><category>paper</category><category>scala</category><category>theory-in-practice</category><category>essence-of-functional-programming</category></item><item><title>Theory in Practice</title><description>&lt;p&gt;I’m starting a series of blog posts, published weekly, called “Theory in Practice.” These will take papers I read from the world of academia and attempt to reiterate them in simpler, more practical terms. One way I will do this is to take the examples, often in &lt;a href="http://www.haskell.org/haskellwiki/Haskell"&gt;Haskell&lt;/a&gt;, and rewrite them in a more practical language, such as &lt;a href="http://www.scala-lang.org/"&gt;Scala&lt;/a&gt;. I’ll also add more real world applications, if needed.&lt;/p&gt;

&lt;p&gt;Since my interests are currently in the world of programming languages and functional programming, I will start this series with a set of foundational papers in this subject area.&lt;/p&gt;

&lt;p&gt;My goal with this series is to open the world of academic papers to a more general audience, as I’ve found that reading these papers has helped me in my day-to-day work greatly, and I hope that my blog posts will have a similar effect on others.&lt;/p&gt;

&lt;p&gt;The first part the series will be on &lt;a href="http://homepages.inf.ed.ac.uk/wadler/topics/monads.html#essence"&gt;“The essence of functional programming”&lt;/a&gt; by Philip Wadler, and will be published this week.&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/7080543745</link><guid>http://mitchellhashimoto.com/post/7080543745</guid><pubDate>Thu, 30 Jun 2011 06:23:23 -0700</pubDate><category>theory-in-practice</category></item><item><title>Welcome to Ruby. We Have Many Rubies.</title><description>&lt;p&gt;Although I consider myself (and I’m proud to be) a polyglot, most of my open source code is Ruby. I’ve been a Rubyist for almost 5 years now and it is still my language of choice for starting projects. Professionally, I’ve begun to use Python in the work-place, and in the process of learning Python I’ve had a hard time understanding the various Python implementations. Additionally, I know friends coming to Ruby who have trouble understanding the reasoning behind all the different Ruby implementations.&lt;/p&gt;

&lt;p&gt;As such, I’m going to give a brief overview of the major Rubies available, their purpose, their development status, and my opinion of them. I’ll cover &lt;strong&gt;Matz’s Ruby (MRI or CRuby)&lt;/strong&gt;, &lt;strong&gt;Ruby Enterprise Edition (REE)&lt;/strong&gt;, &lt;strong&gt;JRuby&lt;/strong&gt;, &lt;strong&gt;Rubinius (rbx)&lt;/strong&gt;, &lt;strong&gt;MacRuby&lt;/strong&gt;, &lt;strong&gt;IronRuby&lt;/strong&gt;, and &lt;strong&gt;MagLev&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The world of Rubies is unlike other languages, such as Python, where I would guess 95%+ use CPython exclusively. It is not uncommon for a single Ruby developer to use Rubinius at home, JRuby for production deployment, and MacRuby for desktop development.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2&gt;Matz’s Ruby Interpreter&lt;/h2&gt;

&lt;p&gt;Matz’s Ruby interpreter, or more commonly called MRI, is the original Ruby interpreter. This is the one you get by default from the official &lt;a href="http://www.ruby-lang.org/en/"&gt;Ruby website&lt;/a&gt; or the one you probably get if you install Ruby via your package manager.&lt;/p&gt;

&lt;p&gt;MRI is also where all the new Ruby features land first, and as such is currently the place where Ruby moves forward. Other implementations strive to reach compatibility with all Ruby that works with MRI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical detail:&lt;/strong&gt; You may see some people reference “YARV.” YARV is the Ruby VM powering Ruby 1.9, and stands for “Yet Another Ruby VM.” YARV technically replaced MRI (which powered 1.8), although Ruby 1.9 is still known as MRI.&lt;/p&gt;

&lt;p&gt;My opinion: MRI is still the most mainstream Ruby. It is maintained by the Ruby-dev team and when someone is a “Ruby programmer” they’re usually referring to this Ruby. I personally still run this Ruby as my default at home.&lt;/p&gt;

&lt;h2&gt;Ruby Enterprise Edition&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.rubyenterpriseedition.com/"&gt;Ruby Enterprise Edition&lt;/a&gt; (or REE for short) is a fork of MRI (Ruby 1.8) which adds some optimizations which make running Ruby in production more performant. Some of the optimizations it adds:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Copy-on-write friendly garbage collector, which makes forking much less expensive.&lt;/li&gt;
&lt;li&gt;Improved memory allocator&lt;/li&gt;
&lt;li&gt;Tunable GC settings, important for servers!&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;My opinion: I don’t have a lot of experience with REE. Many people, such as &lt;a href="http://twitter.com"&gt;Twitter&lt;/a&gt;, use it in production with great success. I’ve heard nothing but good things about it, but prefer JRuby for deployment myself.&lt;/p&gt;

&lt;h2&gt;JRuby&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://jruby.org"&gt;JRuby&lt;/a&gt; is a complete Ruby implementation written in Java on top of the JVM, which provides complete interaction with Java libraries.&lt;/p&gt;

&lt;p&gt;For those new to the concept of additional languages on top of the JVM, this may seem like a huge “why?” The JVM is mature, battle-tested, and exceptionally performant. The Java ecosystem is filled with every library imaginable and is the de facto enterprise language. By putting Ruby on top of the JVM you gain numerous benefits:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Portability and speed of the JVM&lt;/li&gt;
&lt;li&gt;Every Java library becomes a Ruby library&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;My opinion: JRuby is amazing. It can even compile most MRI C extensions (think about that for a moment). Also, I’ve found deploying web applications as &lt;code&gt;war&lt;/code&gt; files the easiest method for deployment available. JRuby also beats MRI in many benchmarks. Its fast!&lt;/p&gt;

&lt;h2&gt;Rubinius&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://rubini.us/"&gt;Rubinius&lt;/a&gt; is a new virtual machine build from the ground up for Ruby. It is written in C++ and can &lt;a href="http://en.wikipedia.org/wiki/Just-in-time_compilation"&gt;JIT&lt;/a&gt; Ruby code to LLVM bytecode. Rubinius can execute Ruby &lt;em&gt;fast&lt;/em&gt;, far faster than MRI. The performance hits to Rubinius come from C extensions, which are slower than MRI.&lt;/p&gt;

&lt;p&gt;Brian Ford, one of the developers behind Rubinius, posted a good &lt;a href="http://rubini.us/2011/02/25/why-use-rubinius/"&gt;Why Use Rubinius?&lt;/a&gt; article that is worth reading.&lt;/p&gt;

&lt;p&gt;My opinion: Rubinius is clearly the future of Ruby VMs. The C++ implementation is beautiful and extensible, whereas the MRI code base is a mess of spaghetti C. Rubinius is extremely performant, and there are a lot of forward-thinking ideas within the VM itself. Rubinius runs most Ruby code, but still hasn’t replaced MRI for me as my default Ruby for edge-case reasons. I recommend giving Rubinius a shot if you havent.&lt;/p&gt;

&lt;h2&gt;MacRuby&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://www.macruby.org/"&gt;MacRuby&lt;/a&gt; is a fork of Ruby 1.9 made by Apple, Inc. MacRuby compiles to LLVM bytecode and can interface with all of Cocoa. MacRuby can even do things like &lt;a href="http://www.macruby.org/documentation/gcd.html"&gt;Grand Central Dispatch&lt;/a&gt; elegantly.&lt;/p&gt;

&lt;p&gt;The point of MacRuby is to allow building Mac applications with a Ruby that is deeply integrated with Mac, such that performance doesn’t suffer and resulting applications are truly native.&lt;/p&gt;

&lt;p&gt;Cool use case: &lt;a href="http://twitter.com"&gt;Twitter&lt;/a&gt; uses MacRuby to unit test much of their Cocoa libraries that their iOS and Mac native clients use. This makes sense thanks to Ruby’s beautiful test libraries.&lt;/p&gt;

&lt;p&gt;My opinion: If you’re making a Mac app, you should really use MacRuby. You can punt the super high-performance stuff to Objective-C and have MacRuby interface with it. Its a no-brainer if you’re a Ruby developer looking to make a Mac app.&lt;/p&gt;

&lt;h2&gt;IronRuby&lt;/h2&gt;

&lt;p&gt;This is here for completions sake. IronRuby is Ruby on top of the .NET runtime. This is exactly analogous to JRuby and the JVM.&lt;/p&gt;

&lt;h2&gt;MagLev&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://ruby.gemstone.com/"&gt;MagLev&lt;/a&gt; is built by &lt;a href="http://gemstone.com/"&gt;GemStone&lt;/a&gt; and it is Ruby on top of a smalltalk virtual machine. It has a JIT as well as an impressive built-in persistence system across multiple VMs.&lt;/p&gt;

&lt;p&gt;My opinion: I’m not aware of any people using MagLev in production personally, but its certainly worth watching.&lt;/p&gt;

&lt;h2&gt;Playing with Rubies&lt;/h2&gt;

&lt;p&gt;Want to play with other Rubies easily? Just use the &lt;a href="http://rvm.beginrescueend.com/"&gt;Ruby Version Manager&lt;/a&gt; (or &lt;code&gt;rvm&lt;/code&gt; for short) which makes it dead simple to install multiple Ruby versions and implementations side by side.&lt;/p&gt;

&lt;p&gt;Now, can someone make one of these posts for Python? Thanks!&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/3849626712</link><guid>http://mitchellhashimoto.com/post/3849626712</guid><pubDate>Sun, 13 Mar 2011 22:13:00 -0700</pubDate><category>ruby,</category><category>rubinius,</category><category>jruby</category><category>ironruby</category><category>maglev</category></item><item><title>CloudFormation: The Big Picture</title><description>&lt;p&gt;Amazon announced &lt;a href="http://aws.amazon.com/cloudformation/"&gt;CloudFormation&lt;/a&gt; to the public yesterday, and while the general opinion I could glean from various sources shows that people are excited about this new technology, many are still unsure what it is and how it fits into their current cloud workflow. I feel as though I have a firm grasp on CloudFormation and will attempt to answer some questions here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I’m definitely not a representative of Amazon in any way, and anything here is simply my educated opinion on the matter.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2&gt;What is it?&lt;/h2&gt;

&lt;p&gt;CloudFormation is best described as an &lt;em&gt;infrastructure provisioning tool&lt;/em&gt; based on a declarative language (expressed in JSON, in this case). CloudFormation takes the declarative file (a “template”) and uses it to orchestrate the creation of various cloud services and hook them up together (resulting in a “stack”).&lt;/p&gt;

&lt;p&gt;The difference between this and Chef or Puppet, is that Chef and Puppet are &lt;em&gt;configuration management tools&lt;/em&gt; and work best with installing and configuring software on new nodes. Some people have used configuration management for launching virtual machines and servers and so on, but this is an exception, and not the norm.&lt;/p&gt;

&lt;p&gt;Chef and Puppet are complementary tools to CloudFormation. CloudFormation starts the server orchestration act and configuration management tools complete it.&lt;/p&gt;

&lt;h2&gt;Where does it fit in my current workflow?&lt;/h2&gt;

&lt;p&gt;It doesn’t, &lt;em&gt;yet&lt;/em&gt;. CloudFormation is really great at describing the infrastructure of a single application, service, or cluster, and bringing up the entire infrastructure as one atomic operation. However, CloudFormation doesn’t yet provide any way to incrementally improve and re-provision infrastructure, which is most of the battle when doing any Ops work. There are some &lt;a href="https://forums.aws.amazon.com/thread.jspa?threadID=61219&amp;tstart=0"&gt;hints from Amazon&lt;/a&gt; that they are thinking about this for the future.&lt;/p&gt;

&lt;p&gt;However, if you’re looking to bring up a new service or application, CloudFormation is far superior to writing manual launch scripts. This is very nice.&lt;/p&gt;

&lt;h2&gt;So, does CloudFormation matter at all?&lt;/h2&gt;

&lt;p&gt;Yes! Infrastructure provisioning is a space which is currently lacking a mainstream tool. CloudFormation is a good step in that direction, and therefore everyone should learn about it, but it is not the end-all-be-all. Certainly if you use AWS exclusively you should pay close attention, since I’m sure its innovation in the future will be important and useful.&lt;/p&gt;

&lt;p&gt;However, we need an &lt;strong&gt;open source, cloud-agnostic solution&lt;/strong&gt; to this problem. Libraries such as &lt;a href="https://github.com/geemus/fog"&gt;Fog&lt;/a&gt;, &lt;a href="http://boto.cloudhackers.com/"&gt;Boto&lt;/a&gt;, &lt;a href="http://incubator.apache.org/libcloud/"&gt;libcloud&lt;/a&gt;, etc. are not the answer. These libraries are just that… libraries to cloud APIs.&lt;/p&gt;

&lt;p&gt;Ideally, we would have a declarative language to define infrastructure (incrementally, as well), and tools to consume this language and use the various libraries noted previously to spin up cloud infrastructure, perhaps even across different cloud providers.&lt;/p&gt;

&lt;p&gt;CloudFormation is a brilliant move by AWS and is a technology worth watching, but at this stage its uses are limited, and it leaves space open for an open source alternative, which I hope will come about.&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/3526628232</link><guid>http://mitchellhashimoto.com/post/3526628232</guid><pubDate>Sat, 26 Feb 2011 10:09:00 -0800</pubDate><category>aws</category><category>cloudformation</category><category>ops</category></item><item><title>Flexible Local AWS Credentials Management</title><description>&lt;p&gt;The &lt;a href="http://aws.amazon.com/"&gt;Amazon Web Services&lt;/a&gt;(AWS) command line tools require certain environmental variables to be set up, such as &lt;code&gt;EC2_HOME&lt;/code&gt; for EC2 and &lt;code&gt;AWS_ACCESS_KEY_ID&lt;/code&gt; and so on. Most people throw this in their &lt;code&gt;bashrc&lt;/code&gt; file and call it good, but this quickly becomes inflexible if you have to manage more and more accounts.&lt;/p&gt;

&lt;p&gt;For example, I happen to manage 4 separate AWS accounts (my personal account and 3 other projects).&lt;/p&gt;

&lt;p&gt;This post outlines how I manage my credentials in a DRY (Don’t-Repeat-Yourself) and flexible way, such that I could easily add more credentials in the future if I needed to.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2&gt;Directory Structure&lt;/h2&gt;

&lt;p&gt;I maintain a very specific directory structure for my AWS related files:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~/.aws
|- bashrc
|- credentials/
|-- setup/
|---- personal
|-- personal/
|- keys/
|-- personalkey.pem
|- ec2/
|- cloudformation/
|- ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I’ll explain each below:&lt;/p&gt;

&lt;h4&gt;&lt;code&gt;bashrc&lt;/code&gt;&lt;/h4&gt;

&lt;p&gt;This file is the main hook that my main &lt;code&gt;bashrc&lt;/code&gt; (at &lt;code&gt;$HOME/.bashrc&lt;/code&gt;) sources. It sets up the various enabled AWS modules and also defines the function for selecting AWS credentials.&lt;/p&gt;

&lt;p&gt;The basic idea is to consolidate all the global and unchanging AWS related environmental variables into a single bash file, so that it is easy to add new services without cluttering my main &lt;code&gt;bashrc&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You’ll see later that the changing environmental variables (those related to authorization) live in specific credentials files which are enabled using the &lt;code&gt;aws_credentials&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;You can view this file &lt;a href="https://github.com/mitchellh/dotfiles/blob/master/aws/bashrc"&gt;in my dotfiles repo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To enable it, add a line like this to your main &lt;code&gt;bashrc&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;test -f "$HOME/.aws/bashrc" &amp;&amp; . "$HOME/.aws/bashrc"
&lt;/code&gt;&lt;/pre&gt;

&lt;h4&gt;&lt;code&gt;credentials/&lt;/code&gt;&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;credentials&lt;/code&gt; directory is in charge of holding all files related to site-specific credentials as well as the bash scripts to setup the environmental variables. There is always a &lt;code&gt;setup/&lt;/code&gt; folder within this directory which contains the bash scripts to toggle different site keys. For example, I may have a &lt;code&gt;personal&lt;/code&gt; file in &lt;code&gt;credentials/setup/personal&lt;/code&gt; which looks like the following:&lt;/p&gt;

&lt;script src="https://gist.github.com/844112.js"&gt; &lt;/script&gt;&lt;p&gt;As you can see, it simply sets the required AWS environmental variables. Easy! But how do you enable this? Use the &lt;code&gt;aws_credentials&lt;/code&gt; function in your terminal, anywhere:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;aws_credentials personal
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will find the &lt;code&gt;credentials/setup/personal&lt;/code&gt; file and load it for your current shell.&lt;/p&gt;

&lt;p&gt;Also important to note, I store all the required files such as the certificates for API calls in a special &lt;code&gt;credentials/SITENAME&lt;/code&gt; directory (&lt;code&gt;personal&lt;/code&gt;, in this case).&lt;/p&gt;

&lt;h4&gt;&lt;code&gt;keys/&lt;/code&gt;&lt;/h4&gt;

&lt;p&gt;I store all my EC2 private keys in this directory for easy access with SSH. For example, my personal account has a &lt;code&gt;mh_key.pem&lt;/code&gt;. To SSH into one of my instances, I just do the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ssh -i ~/.aws/keys/mh_key.pem ubuntu@my-ec2-ip.com
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I’m still looking to improve this, but it works fine for me now.&lt;/p&gt;

&lt;h4&gt;&lt;code&gt;ec2/&lt;/code&gt;, &lt;code&gt;cloudformation/&lt;/code&gt;, etc.&lt;/h4&gt;

&lt;p&gt;I extract the command line tools for the various AWS services and place them directly in the &lt;code&gt;.aws&lt;/code&gt; directory. I may pull these out further into a &lt;code&gt;services&lt;/code&gt; directory or something in the future but for now it works fine. You can see how the various services are enabled in my AWS bashrc (linked to above). Each service has its own way of being enabled, so its easiest to just do it manually for each new service.&lt;/p&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;My method of credentials management isn’t yet perfect, but its much improved from when I started to a point where its very easy to add new services, add new credentials, change existing credentials, switch sites, etc. I plan on further improving this as time goes on, but hopefully this post is enough to get you started with managing your growing number of AWS credentials.&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/3505121069</link><guid>http://mitchellhashimoto.com/post/3505121069</guid><pubDate>Fri, 25 Feb 2011 09:23:00 -0800</pubDate><category>aws</category></item><item><title>Let's Get Back to Business</title><description>&lt;p&gt;Five years ago, and for about two years after that, I was an avid blogger. I maintained a personal blog that focused on PHP (specifically the &lt;a href="http://framework.zend.com"&gt;Zend Framework&lt;/a&gt;) and a year later I launched a successful blog on Erlang, known as &lt;a href="http://spawnlink.com"&gt;spawn_link&lt;/a&gt;. Both blogs had a readership of over 500 people, which, while not trying to brag, I was proud of.&lt;/p&gt;

&lt;p&gt;Though both blogs brought multiple serious job offers, it was my personal blog which got me my first two jobs in the tech industry (note that I was only 17 when I started blogging!). My first job was at &lt;a href="http://zend.com"&gt;Zend&lt;/a&gt; as a contractor doing screencasts for the &lt;a href="http://framework.zend.com"&gt;Zend Framework&lt;/a&gt;, and my second job, and still my current employer, was with &lt;a href="http://citrusbyte.com"&gt;Citrusbyte&lt;/a&gt;, a modern web development shop (which introduced me to the Ruby programming language).&lt;/p&gt;

&lt;p&gt;Both jobs kept me busy, &lt;em&gt;super busy&lt;/em&gt;, and the result was that I stopped blogging!&lt;/p&gt;

&lt;p&gt;The past few years I’ve worked with some extremely smart people, had some unbelievable experiences, and have grown — in many ways — at a rapid speed. There is still so much out there I want to do and things to learn, but I think my experiences the past few years and ongoing deserve to be put down to “ink” for others to gain from.&lt;/p&gt;

&lt;p&gt;And that’s my goal with this blog: Let’s get back to business, the business of giving back for everything that I’ve gained.&lt;/p&gt;</description><link>http://mitchellhashimoto.com/post/2869215320</link><guid>http://mitchellhashimoto.com/post/2869215320</guid><pubDate>Fri, 21 Jan 2011 21:53:00 -0800</pubDate></item></channel></rss>

