Live data from Hacker News

Functional Python Programming

docs.python.org

1–10 of 105 posts

Re: Functional Python Programming

#3

How new is this? Seems like there is more functional tools in Python than I remember. Didn't see the new 'match' statement in this doc.

Is the match-case statement a functional concept? I see it in functional languages but I'm not sure it is inherently functional...

Re: Functional Python Programming

#4
Thanks for posting this. Many years ago (2006?) I was a just-out-of-university programmer and a friend of a friend who wrote Python for Canonical sat me down and tried to teach me functional programming using Python. I was a poor learner: I didn't 'get it' (functional programming in general) and, to my regret, learned nothing.

Much time has passed and I hope I'm a more aware and open-to-new-things person today :) I use Python these days though in a traditional procedural / OO way. This post reminded me that maybe I should look into writing it functional-style. Thankyou!

Re: Functional Python Programming

#5
post #3

How new is this? Seems like there is more functional tools in Python than I remember. Didn't see the new 'match' statement in this doc.

Is the match-case statement a functional concept? I see it in functional languages but I'm not sure it is inherently functional...

functional I can't say, but match was highly related to structural typing which was very much central in FP/LP culture

Re: Functional Python Programming

#7
post #3

Earlier quoted context omitted.

Is the match-case statement a functional concept? I see it in functional languages but I'm not sure it is inherently functional...

functional I can't say, but match was highly related to structural typing which was very much central in FP/LP culture

Think this is answer. It isn't technically needed to be called 'functional', but it is so integral to type systems that it seems to be used in all functional languages. Maybe we can call 'match' statements an emergent phenomena of functional languages.

Re: Functional Python Programming

#8
Sadly, Python is a pretty poor functional language.

The core of functional programming is about avoiding mutable states, not much about anonymous functions or passing functions as data.

To do proper functional programming in Python, there should be IMO:

- a way to enforce non-mutable variables/objects;

- non-mutable collections;

- proper support for recursion and tail-recursion optimization;

- a better syntax for anonymous functions than single statement lambdas.

Generators are nice, but do not have much to do with functional programming.

Re: Functional Python Programming

#10
post #8

Sadly, Python is a pretty poor functional language. The core of functional programming is about avoiding mutable states , not much about anonymous functions or passing functions as data. To do proper functional programming in Python, there should be IMO: - a way to enforce non-mutable variables/objects; - non-mutable collections; - proper support for recursion and tail-recursion optimization; - a better syntax for an…

I agree but it's not so dire, the tuple type (and variants like namedtuple) is pretty powerful, non-mutable and often my first choice for data structure in python. Everything else can be built on top of it if you're really motivated.
Post reply on HN