I feel my chain being yanked...

On Wed, Aug 24, 2011 at 4:48 PM, Andrew Grimm <[email protected]>wrote:

> Do functional programmers try to manage IO side effects by trying to
> do as much of the input as early as possible, and leave as much of the
> output as late as possible, or is there more to it than that?
>

It's not so much about the timing of IO, it's about how much of your project
is concerned with the nitty-gritty details of it.
For instance, Don Stewart's XMonad window manager. An X window manager would
seem like an inherently stateful, mutable sort of program, but he managed to
slice the problem up in such a way that the majority of it is pure, with a
very thin IO shell around it.

It should be pointed out that not doing IO (or relying on side-effects) in
the majority of your code is good practice in Ruby too - it makes it easier
to test and refactor because you don't have to monkeypatch away the output,
or deal with the consequences of having changed state in a test run (cf
Database Cleaner).


> If you were trying to program in the functional programming paradigm
> in Ruby, would you have to understand monads first, or is that more of
> a requirement for specific functional programming languages such as
> Haskell?
>

Forget monads, seriously. It's just a design pattern[1] - it's like someone
saying "you can't understand Ruby until you've fully grokked MVC". It just
isn't so.
They _are_ useful, it's true, but in my first three years of using Haskell,
I barely wrote any monadic code that wasn't in IO.

mark
[1] with perhaps the distinction that design patterns in Haskell can
disappear into the type system, the same way the Iterator pattern in Ruby
disappears into Enumerable

-- 
A UNIX signature isn't a return address, it's the ASCII equivalent of a
black velvet clown painting. It's a rectangle of carets surrounding a
quote from a literary giant of weeniedom like Heinlein or Dr. Who.
        -- Chris Maeda

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to