lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

It was thus said that the Great Journeyer J. Joh once stated:
> Hi Javier Guerra Giraldez,
> I must say I am sorry. I didn't intent to make you write this much writings
> to me.
> And I understand what you and Steve and Sean trying to say now.
> So far I tried not to face a need to learn functional programming. 

  The concepts of functional programming are (I think) rather easy to
understand.  It's wrapping your brain around the concepts to get certain
classes of programs written that's hard.

  For instance, the following list is about 80% of what functional
programming is all about:

	1. no global variables
	2. functions can only use the data given to it via parameters

#1 is pretty easy to understand---there are no global variables.  It might be
harder to adapt to this, although not impossible (even in C I try to avoid
the use of globals as much as possible).

#2 is also easy to understand (and follows from #1).  Without global
variables, a function can only use what it is given.  These two rules make
it easier to reason about code, test the functions in isolation, and are
relatively easy to do in non-functional languages.  The next item is harder
to understand though:

	3. variables are immutable (that is---once set, they can't change)

This is where functional programming starts to get "hard," conceptually. 
Once a variable is assigned, it can't be modified.  Because of this,
functions in functional languages tend to be short and rely upon recursion
(the only way to do loops without modifying a variable) and thus, functional
langauges also tend to support tail call optimizations (which is useful even
in imperative languages).  

  But for insight into functional programming, you can't do worse than start

(summary:  He attempts to design Pac-Man in a functional style)

  -spc (No, really, the first two items will get you most of the way
	to functional programming)