His code not ‘functional’ or ‘elegant’

In the middle of another gold card, this one on Actors (PDF), a concurrent programming abstraction that Scala borrowed from Erlang. The Scala short tutorial on actors isn’t much help, at least not to someone who’s spent as little time with Scala as I have; mostly Mr. Haller just seems to show you the source code from the examples directory and say “see”? But I persevere.

In the course of said perseverance, I did run across one interesting link, which I post by way of bookmarking: Functional Java, “an open source library that aims to prepare the Java programming language for the inclusion of closures [and] serves as a platform for learning functional programming concepts by introducing these concepts using a familiar language.” Which sounds like exactly what Code Monkey needs.

6 thoughts on “His code not ‘functional’ or ‘elegant’

  1. For what it’s worth, trying to reconcile Actors and functional programming in my head is what lead to the whole “how does functional programming justify causing effects apart from returning an expression” question from exactly one century ago (in internet years). It’s no stretch to think of an Actor being written functionally, but I get tripped up trying to reconcile a system of constantly and asynchronously mutating Actors with FP priorities.

  2. Yeah, you’ll note that the pingpong example still has a mutating counter.

    I think I understand actors a little better now, but I still don’t understand how they’re supposed to solve the problems Haller and Odersky claim they solve — particularly exposing hidden control flow. (And the Functional Java implementation was a disappointment — it works, and it’s probably elegant, but the code’s much less readable than the corresponding Scala code.)

    This weekend I’ll take my laptop to a cafe with free wi-fi and actually type up actors and monads, since the intention to do it at home never seems to survive entering the building.

  3. (a decade in internet-time later:) Oh, wait — was that last comment directed at me? I read it as a David-not-Moles inquiring of a David-signified-Moles, but my Occam’s razor has been a bit dull, lately.

    In case the PBX question was for me: I’ve been outlining a project that, in my ideal world, could eventually be migrated onto a peer-to-peer infrastructure. The core structure that I’m working with is strongly functional but/and would deteriorate pretty badly outside the low-latency, high-availability environment of a single computer. Thinking about how to encapsulate and distribute it lead to questions of concurrency, which seems to lead naturally these days to Actors. In the end, I think I’ve decided to isolate the functional core inside a procedural wrapper.

    (Ye gods, I feel like such a poser just saying that much. Honestly, my current side project is “raising a baby” — programming, I expect, will come back in a few years. If you’re still curious, drop me an email.)

  4. Yeah, apparently it’s “David” when I log in and “David Moles” when I just type stuff in from scratch. (I could change that but then this thread would get real confusing.)

    Dunno if you saw my REST post from a few days ago, but that approach seems oddly FP-like in a way I can’t quite articulate.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s