On Fri, 2012-12-28 at 09:13 +0100, Red wrote: > Why is immutable data considered necessary for functional > programming style? Can't a a programmer or programmer just do the > same thing with mutable data, but not mutate it? That is, > couldn't Python be used for functional programming?
Because immutable state is a concept entirely missing from functional languages: functional languages have no tools for handling mutable state. OK Haskell has introduced arrays and indexing but it remains a dark corner for most use cases. Yes, but… if a language provide features you would be writing in a non-idiomatic way to simply ignore those features. The issue here is that a language will embody a computational model and an idiomatic mode of expression of algorithms. A language should always be used in as idiomatic way as possible. To use an imperative language in a purely functional way will lead to poor code. Conversely all use of mutable shared state is a code smell that should lead to a refactoring. Python cannot be used for functional programming in the purist sense due to lack of single assignment, presence of for and while loops, and lack of tail recursion optimization. However with higher order functional, list, set and dictionary comprehensions, many of the techniques and idioms of functional programming can, indeed should, be used when programming in Python. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:[email protected] 41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected] London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part
