erlang

Erlang, Yaws, and ETags

April 3rd, 2008  |  Published in erlang, REST, yaws  |  Bookmark on Pinboard.in

Regarding my “RESTful Services with Erlang and Yaws” article on InfoQ.com, Sam Ruby said:

This otherwise excellent article fails my ETag test.

When Sam speaks, I listen, so I’ve given his feedback a lot of thought.

As I wrote in a comment on Sam’s blog, the Erlang/Yaws RESTful services I work on do indeed support conditional GETs, so at least my day-to-day work passes his ETags test. As for the article, there are two ways to think about it:

  1. If you focus on the “RESTful Design” portion of the article, then yes, I could have added a “think about where you need to support conditional GETs” item to the “key areas to pay attention to” list.

  2. If you focus on the Yaws/Erlang aspect of the article, then keep in mind that dealing with ETags requires dealing with HTTP headers such as If-none-match and the ETag header itself. The article already shows you how to read request headers and write reply headers, though, and how you actually create specific ETag values for use in the headers depends on the particulars of your resources — Leonard Richardson’s and Sam’s excellent book already covers this pretty well.

I intended the focus of the article to be more about item 2 than item 1, so I think not specifically addressing ETags is OK.

One thing I should have included, though, is how to parse POST data. You use the yaws_api:parse_post/1 function for that, passing in an arg record. For typical form data, it’ll give you back a list of key/value pairs over which you can iterate, or from which you can extract expected key/value pairs using yaws_api:postvar/2 (or even proplists:lookup/2 or lists:keysearch/3, if you like). See the documentation at the Yaws website for more details, but all in all, handling POST data in Yaws is fairly trivial.

RESTful Services with Erlang and Yaws

March 31st, 2008  |  Published in erlang, REST, services, yaws  |  Bookmark on Pinboard.in

Today InfoQ.com published a new article I’ve written entitled “RESTful Services with Erlang and Yaws.” Stefan Tilkov recently asked me if I had anything to contribute to InfoQ, and I thought an article on that topic might be interesting, as I hadn’t before seen anything covering REST and Erlang together.

I think it’s one of those articles that could be much, much longer and far more detailed if space (and time) permitted, but hopefully there’s enough there to whet your appetite if you’re considering developing RESTful web services in Erlang. I really can’t say enough good things about using Erlang and Yaws for this purpose — it’s quite a solid platform.

I’ll be giving a talk on the same topic at both JAOO Brisbane and JAOO Sydney at the end of May and beginning of June, respectively.

Back from QCon

March 15th, 2008  |  Published in commentary, conferences, erlang  |  Bookmark on Pinboard.in

I just returned home from QCon London, and its excellence exceeded my expectations. As usual, the quality of speakers QCon attracts (just like JAOO) is outstanding, and they cover a very wide variety of topics.

Kent Beck‘s keynote was excellent. It was about developer responsibility, developer integrity, and the relationships developers have with those around them (here’s a good summary). Extremely insightful, not unexpectedly of course, and covering important topics that are unfortunately often taboo among technical folk.

It’s been awhile since I spent any quality time with Kent, but we did manage to sneak off to a back room at the speaker party on Thursday evening and get 20 minutes or so of conversation in, which is better than nothing. Given that the first two to drop in were Jim Webber and Joe Armstrong, though, neither of us minded the extra company. Generally, though, I think I could easily spend a couple solid days talking to Kent about development issues.

I spoke in Stefan Tilkov‘s track on Thursday, and I thought it went OK. Stefan has already provided detailed notes on each talk (except his own, which was really good) on his blog, so I won’t bother with repeating any of that. I got to meet Paul Fremantle in person for the first time, which was nice, though I have to say I remain puzzled by his “REST is too hard for the average developer” claim he made in his talk, since it definitely doesn’t match my recent experiences with watching others learn it and apply it. I’ve heard Sanjiva say the same thing before as well, so I wonder if it’s just something they keep telling themselves, hoping it will come true if they repeat it enough. ;-)

On Friday I thoroughly enjoyed Simon Peyton-Jones‘s Haskell talk and Joe Armstrong‘s Erlang talk. Both were excellent speakers, and both talks ventured into areas that I’m sure many of the attendees were not familiar with, so I’m sure most everyone who listened learned a lot. Thankfully there were no “Haskell vs. Erlang” wars, but that’s not surprising given that Simon and Joe are friends, plus they know that that argument serves neither language.

The best part of the week, though, was getting to meet and hang out with Joe and other Erlang folk. Joe’s really an excellent guy. He’s quite energetic, and his brain just doesn’t stop. He’s curious about a lot of technical things beyond Erlang, and I found discussions with him to be full of interesting questions and insights. Given the fact that I work with Erlang quite a lot these days, my hope going in was simply that I’d get a chance to just say hi to him, but I turned out to be lucky enough to spend many hours with him over the course of the conference. I also met Francesco Cesarini, a well-known and long-time Erlang consultant, whom I’m sure has probably forgotten more Erlang than I’ve learned so far. I also met Alexis Richardson, who works on RabbitMQ, the right way to implement AMQP. Francesco graciously invited me to speak at the Erlang Exchange this summer, so I’ll be seeing them all again before too long to talk even more about what’s quickly become one of my favorite programming languages.

Congrats to Floyd, Kresten, and the whole QCon team for putting on yet another excellent conference. I’m looking forward to JAOO Australia (in both Brisbane and Sydney) next!

Damien Katz Criticizes Erlang

March 10th, 2008  |  Published in code, erlang, functional  |  Bookmark on Pinboard.in

Damien Katz has been using Erlang for CouchDB, and has posted some criticisms of the language and runtime based on his experiences with them. Erlang, like any language, has its issues, and Damien’s criticisms are mostly reasonable and are worth reading. Well, except for this one:

Immutable variables in Erlang are hard to deal with when you have code that tends to change a lot, like user application code, where you are often performing a bunch of arbitrary steps that need to be changed as needs evolve.

In C, lets say you have some code:

int f(int x) {
x = foo(x);
x = bar(x);
return baz(x);
}

And you want to add a new step in the function:

int f(int x) {
x = foo(x);
x = fab(x);
x = bar(x);
return baz(x);
}

Only one line needs editing,

Consider the Erlang equivalent:

f(X) ->
X1 = foo(X),
X2 = bar(X1),
baz(X2).

Now you want to add a new step, which requires editing every variable thereafter:
f(X) ->
X1 = foo(X),
X2 = fab(X1),
X3 = bar(X2),
baz(X3).

If you had to write that code the way Damien did, then yes, that would suck. But here’s a better way to write it:

f(X) ->
    lists:foldl(fun(F, Last) -> F(Last) end,
        X, [fun foo/1, fun fab/1, fun bar/1, fun baz/1]).

This code applies the anonymous function passed as the first argument to lists:foldl for each element of the third argument — the list of funs, Erlang-speak for functions — starting with the value X as the value passed as Last and using the return value of F(Last) as the next value of Last. The overall return value of lists:foldl is the final value of Last. With this approach, modifying the functions applied to X also requires editing only a single line, specifically the list of funs.

In general, if you’re used to imperative languages and you find yourself writing step-by-step Erlang code like in the original example above, think functions and lists instead.

P.S. If you’ve never seen it, read Damien’s Signs You’re a Crappy Programmer (and don’t know it). One of my favorite blog postings, and I especially like the first two items in his list.

InfoQ Interview

February 26th, 2008  |  Published in commentary, conferences, CORBA, distributed systems, dynamic languages, erlang, HTTP, interview, productivity, REST  |  Bookmark on Pinboard.in

When I spoke at QCon San Francisco last November, Stefan Tilkov interviewed me, and the video is now available on InfoQ.com.

We covered a range of topics: CORBA, dynamic languages, REST, distribution, concurrency, Erlang. Stefan asked some great questions, and I hope I gave some worthwhile answers. Thanks again, Stefan.