TechHui

Hawaiʻi's Technology Community

Just wanted to mention (and I think plenty of other people interested in FP languages already do this) that much of the code that I've written in mainstream/procedural/OO languages ends up being purely functional. I was delighted to hear Rich Hickey, in one of his Clojure videos, say that he does the same thing.

It's just easier to reason about the correctness of purely functional routines. Anybody else here do this?

-- Nate

Views: 70

Replies to This Discussion

Can you give some examples of what it means to write programs in a pure functional style in procedural or OO languages? Do you just mean that you focus on creating immutable data structures? And stateless objects?
Nothing too complicated -- just that I tend to write methods/functions that are purely functional. They neither depend on external state, nor modify any external state. They can do their job solely through parameter input and value return. The fact that they're self-contained means that you can look simply at the text in front of you and figure out what's going on without looking other places to see how values are modified, and it also enables easy re-use since it's decoupled from other state.

Obviously, it's tough to completely get away from stateful programming, but you can segregate things somewhat. I used to do this to some degree in C and C++ and Rich Hickey talks about "writing Java classes with 56 purely functional static methods" (paraphrased, but close), which I'm sure some of his co-workers looked strangely at. :)

This style obviously ends up with you either making a lot of copies or going immutable like you mention and passing around refs/pointers without changing the targets.

-- Nate

Anders Conbere said:
Can you give some examples of what it means to write programs in a pure functional style in procedural or OO languages? Do you just mean that you focus on creating immutable data structures? And stateless objects?
I do this also. When writing imperative code I see if I can:

1) try not to use bindings (variables) if I don't have to do so
2) if I can't do #1 then I use single-assignment bindings, emulating erlang

Often times, this results in tighter code w/ less side-effects.

(It's simplistic and doesn't address mutable structures like Hash and Array. I know)

Bottom line for me is "Just don't go there" :) I would rather just write real FP code.

RSS

Sponsors

web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service