my current Work Stack

  • iOS Objective-C
  • Ruby
  • Mongo
  • Rails/Sinatra
  • jQuery
  • Capistrano
  • Passenger
  • Apache.Nginx
  • Heroku
  • Nodejs
last edited 02.10.2012

here's all my posts so far

02/10 Using the Facebook SDK in an IOS Static Library
04/11 Managing Development or Sometimes work gets in the way of work
12/21 Git Stash: For when your boss|clients|life priorities change
12/09 Picker Fields in Titanium
11/30 An Update on Raphael JS and Charts
10/08 How to make a Native App Form that doesn't suck with Titanium
09/23 Notification Subscriptions in Gowalla
09/21 Developing an API in Rails
08/26 I was promised Event Driven APIs and hoverboards. Where are my hoverboards?
08/14 A Node.js wrapper for Gowalla
08/09 Phusion Passenger Tweaking: Apache stuck in Sending(W)
06/28 HTML 5 is here and breaking old hacks we should have never done!
06/26 Simple PDFkit example in Rails 3
06/23 Raphael.serialize
06/12 Serializing RaphaelJS
06/11 Rails 3 beta4 destroyed my Tie Fighter
05/21 Rails 3 and Shoulda
05/13 Using yaml to configure default options for Paperclip
05/07 It's OK to not be pretentious
04/23 Snippet #1
04/21 I Need Closure
04/16 The Good and Bad of Github
04/08 Fun with Beards, or at least mine

here's some tweets I made

I Need Closure

This morning I was reading in the new Pickaxe, mostly looking for tidbits of Ruby 1.9 glory.

On page 67 I found one of the best and most concise definitions of a closure.

For comparison, here's the first paragraph on closure from Wikipedia:

"In computer science, a closure is a first-class function with free variables that are bound in the lexical environment. Such a function is said to be "closed over" its free variables. A closure is defined within the scope of its free variables, and the extent of those variables is at least as long as the lifetime of the closure itself. The explicit use of closures is associated with functional programming and with languages such as ML and Lisp. Closures are used to implement continuation passing style, and in this manner, hide state. Constructs such as objects and control structures can thus be implemented with closures."

Wow there's a lot of links in there. Here's Dave Thomas' page 67 definition:

closure
variables in the surrounding scope that are referenced in a block remain accessible for the life of that block and the life of any Proc object created from that block.

It reminded me of something a college professor of mine said. That closures were like a sack that you threw a method and some variables into. You could carry that sack around and wherever you opened it, that method would use the variables in the sack.

He also said that electrons in a transistor were like putting a box of puppies in a corner.

blog comments powered by Disqus