August 2010
2 posts
Relaxing Haskell's function definition...
Guess what? Haskell function definitions HAVE to be grouped together.  I’d always just assumed it was convention (a convention that in most cases enhances readability), but it turns out it’s a requirement of the language. What do I mean? Consider the following: Notice that I grouped all of the pattern matches for “sayHello” together in sequence, then plowed through all the...
Aug 16th
5 notes
4 tags
Haskell Web Frameworks
I’ve recently been developing my own sinatra-inspired web framework in Haskell called bird. And though I haven’t exactly accomplished a lot with it (our newborn has somewhat limited the amount of time I have for recreational programming), the endeavor has helped me learn the language.  I’ll compare and contrast a simple web app that responds to a url /echo/:s. If s is a 4 letter...
Aug 1st
4 notes
May 2010
2 posts
bash pipes in haskell
Pipes in bash rock. It’s a beautiful, simple, powerful concept. The rest of the Bash scripting language, is, of course, complete dog shit. But the pipes; oh yes, the pipes. Turns out you can do something similar in haskell. It’s already built in, just in reverse: the “$” operator. Check out my contrived, over-complicated factorial method: The “fac” method...
May 2nd
8 notes
ruby v. haskell (round 3): mutually recursive data...
Continuing my series of posts comparing and contrasting the dynamically-typed imperative language Ruby with the strongly-typed declarative language Haskell, I’ll now examine the abilities of these languages to create mutually recursive data structures. I’d like to model a real-world relationship for the purposes of this post: the relationship between authors and books. An author may...
May 1st
11 notes
April 2010
3 posts
ruby v. haskell continued: a script for converting...
In my last post, I contrasted an algorithm for sorting a list so that it would display column-sorted in an n-column liquid layout. In the case of that stateless algorithm, Haskell clearly wound up looking like the more elegant solution. The Haskell code was readable, “self-documenting”, and concise. The Ruby version was longer, significantly less “self-documenting”, and...
Apr 11th
9 notes
ruby v. haskell: a love tap
I love Ruby. I admit it. We’ve had a hot, steamy love affair for the last two years, and I see no end in sight. But, once, long ago, in a university far far away, I had an intense, one semester fling with another language in an entirely different paradigm: Haskell. Haskell was different. Up to that point, I’d only dated boring, imperative languages like C++ and Java. Haskell was a...
Apr 10th
3 notes
Liquid Layouts and Matrix Transposition
Liquid layouts: the practice (among other things) of rendering a single ul/li group (like this): <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <li>10</li> ...
Apr 4th
12 notes
March 2010
3 posts
class variables and inheritance in Ruby
Stumbling around the rubyverse, I happened across an old article by @jnunemaker (of mongo mapper and twitter gem fame) about class variables and inheritance in Ruby, and realized that though I often use class instance variables (i.e., @ variables in the eigenclass), i rarely use class variables (@@), and that I’d never known about the class variable inheritance gotcha. After following links to...
Mar 27th
34 notes
4 tags
Dupe 0.5.1 includes POST, PUT, and DELETE...
The latest release of my Dupe gem (v0.5.1) includes POST, PUT, and DELETE intercept mocks out of the box. Up to this point, it only had GET intercept mock support. What does this mean in terms of ActiveResource? Now you can run “create”, “save”, and “destroy” on your ActiveResource::Base derived instances and Dupe will mock the services for these out of the...
Mar 14th
7 notes
binder becomes slightly less binding
Based on some valid feedback on my binder gem, I’ve refactored my code, simplified it where possible, and scaled it back to its most basic essentials. The “bind” class method is now packaged in a “Binder” module. When you require ‘binder’, the gem will no longer automatically monkey patch Object, polluting your namespace. Instead, you’ll have to...
Mar 7th
6 notes
February 2010
4 posts
2 tags
ask(me) { for_more }
Because you can never get enough syntactic sugar, I added a more human readable shorthand (tell) for “instance_eval” to my binder gem. class Dog def speak puts "ruff!" end end fido = Dog.new fido.instance_eval do speak end # ==> would print "ruff!" tell fido do speak end # or tell(fido) { speak } # or tell(fido, :to) { speak } # ==> would all print "ruff!"...
Feb 22nd
5 notes
binder: for all your esoteric proc closure needs
After playing around with my newfound ability to bind a proc to a new closure, I found myself wanting to be able to do this in most of my projects. I also found myself repeatedly creating DSL methods that simply evaluated the block passed to them within a new closure. So, what did I do? I created a new gem, aptly titled “binder”. Rewriting my example from my previous post about...
Feb 20th
8 notes
tap that @foo
Ever use the Kernel#tap method? It’s a great way to package up side effects, and avoid adding that annoying single variable at the end of your method. Let’s look at a method that creates and returns a user and (as a side effect) sends off a registration email: def create_user_and_email_registration(attributes) user = User.create! attributes user.send_registration_email ...
Feb 19th
5 notes
4 tags
creating cleaner APIs
After attending the Online Rails Conf yesterday, I was intrigued by the new router api: MyApp::Application.routes do match "/main/:id", :to => "main#home" end How does “match” evaluate to a method? My understanding of scoping with procs/blocks has always led me to build API’s like the old router - e.g., here’s an example of my Dupe model definition...
Feb 19th
10 notes