[TriLUG] What about this is functional programming, and what about it isn't

Steve Litt slitt at troubleshooters.com
Tue Mar 4 11:16:39 EST 2014


Hi all,

Tomorrow night at GoLUG I'm presenting on "Design Patterns in
Python", with one pattern being functional programming.

Being a firm believer in data-centered programming, functional
programming doesn't come easy to me, but I have to include it. So I made
the most functional program I could in 10 hours, the tic-tac-toe
program here:

http://www.troubleshooters.com/linux/presentations/golug_design_patterns_python/tic_proto.py.txt

What I need is feedback about what is, and what is not, functional
programming within this program. Then I'll just point out to the
audience what is, and is not, functional programming, and get the point
across. For instance, if I had to guess, it would be something like
this:

FUNCTIONAL:

* The main logic isn't iteration, it's let_human_move() and
  machine_moves_now() repeatedly call each other recursively, so at
  the top level there's no state but the function args and returns.
* With the exception of a few prints and a couple input accepts, no
  function has side effects: Each function's effect is only on the
  return value.
* Every function's return value is affected only by the function's
  inputs.

NONFUNCTIONAL

* I'm passing around, as an argument and as a return, a huge piece of
  state called "board".
* The internals (implementation) of many of the functions are extremely
  state rich and contain lots of state-depending loops.

I'm sure some of you know a lot more about functional programming than
I do, so it would help me a lot if you could tell me what is, and what
is not, functional programming within this tic-tac-toe program.

Thanks,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance


More information about the TriLUG mailing list