Jun 24 2008

Functional (Meta)?Programming Stunts for Ruby and Groovy (and a Little Perl)

Published by Robert Fischer

After I learned OCaml, my coding mindset was totally distorted. I started writing Java code that looked like this:

  public Collection<Foo> getCertainFoos() {
    return
      CollectionUtils.select(getFoos(), new Predicate() { 
         public boolean evaluate(Object o) {
            return SOME_CONSTANT.equals(((Foo)o).getProperty());
         }
      });
  }

This is kinda ugly in Java, but it’s simply what comes out when I was thinking this in OCaml:

List.find_all (fun i -> SOME_CONSTANT = i#getProperty()) #getFoos()

I also started slapping final everywhere — see Yet Another Reason final Is Your Friend. A ubiquitous use of final actually gave some nice patterns (in the “macro” sense of patterns), but raised all kinds of eyebrows and made my code unmistakable. This lead up to a unique coding style which you can see in my most involved open source project, JConch. Meanwhile, my co-blogger was talking about “The Hole in the Middle” Pattern, which is also a lay-up within FP circles but required some backflips to implement in Java (functional interfaces) and C# (delegates).

It wasn’t until the advent of Ruby and Groovy, though, that functional programming skills really became easier to use. Basically, because of the inline closure’s succinct syntax (and ability to access non-final variables), I could suddenly do all kinds of really fun stuff. This “fun stuff” was exactly the kind of stunts I was pulling in Perl back in the day (see the BEGIN block in my Text::Shift code for a reasonably accessible example), and it was part of the reason I loved Perl so much at the time.

So, I thought I’d share some more of these cute stunts with you.
Continue Reading »

Popularity: 6% [?]

6 responses so far

Jun 20 2008

Water Ice on Mars!

Published by Robert Fischer

Are you ready to celebrate? Well, get ready: We have ICE!!!!! Yes, ICE, *WATER ICE* on Mars! w00t!!! Best day ever!!
— Mars Phoenix Rover (cite)

Wired article is here.

University of Arizona’s page on the Mars Lander has a press release here which includes some pictures.

NY Times just got into the mix here.

Popularity: 1% [?]

No responses yet

Jun 19 2008

Twitter and Blogging

Published by Robert Fischer

Pardon the self-indulgent meta-blogging.

My boss has a blog post about his fondness for Twitter. I had noticed that a lot of my less formal blogs seem to have gotten quiet recently — this one included.

For my part, there was a lot of blog posts that were simply passing thoughts or sharing links I bumped into (link Refactr’s blog post that made me cranky) — those got moved onto my Twitter stream, because it was easier to share them there, and nobody’s complained about missing them.

This leaves just the more thorough blog posts on topics (like Groovy’s list#flatten and the status of Ruby’s libxml) and reasonably significant announcements (like presentations I’m giving).

The topics posts have gotten a bit slow because they take a lot of work to do right (where I define “right” to include 7 Useful Things and Development Acceleration), and I’ve been busy with work on one hand, moving to Durham on the other hand, and trying to launch a website on the third hand.

If you’re missing my link posts, check out my shared items page. If you just can’t get enough of me, subscribe to my feed on Twitter.

(Oh, and BTW, if you haven’t seen this profound truth, you should.)

(Also BTW, if I ever get around to doing my Web 2.0 podcast, I want to be sure to interview the producers behind “Rate My Space” and Paul Douglas. And John Cluberson and Roy Blunt and Tim Ryan. And Arianna Huffington and John Cusack.)

Popularity: 1% [?]

No responses yet

Jun 16 2008

A Groovy Gotcha: list#flatten with a map/pseudobean inside

Published by Robert Fischer

Edit: This fix has been checked into the evolving 1.6 version, and the developers are discussing if it will be in the final 1.5.x release.


Let’s start with the punchline:

def x = [ [a:1, b:2, c:3] ]
def y = x.flatten()
assertEquals([1, 2, 3], y)

Continue Reading »

Popularity: 1% [?]

3 responses so far

Jun 03 2008

The Horror of the Third Reich

Published by Robert Fischer

The new Indiana Jones movie (which I haven’t seen) got me thinking again about the Nazis, and the Berkley podcast I’m listening to (not sure which one) just got to the Third Reich, too. This got me thinking back to Brian’s post, A question I shouldn’t HAVE to ask, and I wanted to expand a bit on some of those thoughts.
Continue Reading »

Popularity: 5% [?]

12 responses so far

« Prev - Next »

Green Web Hosting! This site hosted by DreamHost.