Is Python a functional programming language?

Lie Ryan lie.1296 at gmail.com
Tue May 11 15:59:50 EDT 2010


On 05/12/10 05:25, Chris Rebert wrote:
> On Tue, May 11, 2010 at 11:13 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>> On 5/11/2010 7:11 AM, Lawrence D'Oliveiro wrote:
>>> In message<7xvdavd4bq.fsf at ruckus.brouhaha.com>, Paul Rubin wrote:
>>>
>>>> Python is a pragmatic language from an imperative tradition ...
>>>
>>> I thought the opposite of “functional” was “procedural”, not “imperative”.
>>> The opposite to the latter is “declarative”. But (nearly) all procedural
>>> languages also have declarative constructs, not just imperative ones
>>> (certainly Python does).
>>
>> Python has only two: 'global' and now 'nonlocal'.
>> There are also two meta-declarations: the coding cookie (which would/will go
>> away in an entirely unicode world) and future imports (which are effectively
>> temporarily gone in 3.x until needed again).
>>
>> Newbies sometimes trip over def and class being imperative (executable)
>> statments rather than declarations.
> 
> Er, declarative programming has nothing to do with variable declarations.
> http://en.wikipedia.org/wiki/Declarative_programming
> 

Variable declarations have everything to do with declarative programming.

An imperative way to create a variable is to allocate the memory
yourself and instead of "variables" you have just registers and the
memory; fortunately all popular imperative languages (wisely) picks up
declarative syntax from the declarative paradigm. In Python, the regular
def/class is a pseudo-declaration, but it is also possible to
*imperatively/procedurally* create a class by calling type() and a
function by passing a __call__() to type()'s __dict__ argument.

A fully declarative language just turn everything into declarations
including the "business logic" of the application (and of course,
variable declaration).



More information about the Python-list mailing list