Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9387 > unrolled thread

Functional style programming in python: what will you talk about if you have an hour on this topic?

Started byAnthony Kong <anthony.hw.kong@gmail.com>
First post2011-07-13 05:39 -0700
Last post2011-07-14 03:31 -0700
Articles 9 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  Functional style programming in python: what will you talk about if you have an hour on this topic? Anthony Kong <anthony.hw.kong@gmail.com> - 2011-07-13 05:39 -0700
    Re: Functional style programming in python: what will you talk about if you have an hour on this topic? gene heskett <gheskett@wdtv.com> - 2011-07-13 09:41 -0400
    Re: Functional style programming in python: what will you talk about if you have an hour on this topic? J Kenneth King <james@agentultra.com> - 2011-07-13 09:50 -0400
    Re: Functional style programming in python: what will you talk about if you have an hour on this topic? Terry Reedy <tjreedy@udel.edu> - 2011-07-13 12:29 -0400
    Re: Functional style programming in python: what will you talk about if you have an hour on this topic? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-13 11:09 -0600
    Re: Functional style programming in python: what will you talk about if   you have an hour on this topic? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-07-14 15:32 +1200
      Re: Functional style programming in python: what will you talk about if   you have an hour on this topic? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-14 14:05 +1000
      Re: Functional style programming in python: what will you talk about if you have an hour on this topic? Jonathan Hartley <tartley@tartley.com> - 2011-07-14 03:33 -0700
    Re: Functional style programming in python: what will you talk about if you have an hour on this topic? Jonathan Hartley <tartley@tartley.com> - 2011-07-14 03:31 -0700

#9387 — Functional style programming in python: what will you talk about if you have an hour on this topic?

FromAnthony Kong <anthony.hw.kong@gmail.com>
Date2011-07-13 05:39 -0700
SubjectFunctional style programming in python: what will you talk about if you have an hour on this topic?
Message-ID<2b28da74-f054-4f46-8971-43603ab7cfd3@glegroupsg2000goo.googlegroups.com>
(My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice)

Hi, all,

If you have read my previous posts to the group, you probably have some idea why I asked this question.

I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work.

<personal opinion>
So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag  of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages.
</personal opinion>

I think I will go through the following items:

itertools module
functools module
concept of currying ('partial')


I would therefore want to ask your input e.g.

Is there any good example to illustrate the concept? 
What is the most important features you think I should cover?
What will happen if you overdo it?


Cheers

[toc] | [next] | [standalone]


#9394

Fromgene heskett <gheskett@wdtv.com>
Date2011-07-13 09:41 -0400
Message-ID<mailman.977.1310564481.1164.python-list@python.org>
In reply to#9387
On Wednesday, July 13, 2011 09:38:26 AM Anthony Kong did opine:

> (My post did not appear in the mailing list, so this is my second try.
> Apology if it ends up posted twice)
> 
Actually, it did, but gmail, in its infinite wisdom, thinks an echo of your 
post to a mailing list is a duplicate, and deletes it.  For this exact 
reason, I only use gmail for two or 3 of the nearly 40 lists I'm on.

[...]

Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
He is considered a most graceful speaker who can say nothing in the most 
words.

[toc] | [prev] | [next] | [standalone]


#9395

FromJ Kenneth King <james@agentultra.com>
Date2011-07-13 09:50 -0400
Message-ID<87aaci8f2l.fsf@agentultra.com>
In reply to#9387
Anthony Kong <anthony.hw.kong@gmail.com> writes:

> (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice)
>
> Hi, all,
>
> If you have read my previous posts to the group, you probably have some idea why I asked this question.
>
> I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work.
>
> <personal opinion>
> So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag  of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages.
> </personal opinion>
>
> I think I will go through the following items:
>
> itertools module
> functools module
> concept of currying ('partial')
>
>
> I would therefore want to ask your input e.g.
>
> Is there any good example to illustrate the concept? 
> What is the most important features you think I should cover?
> What will happen if you overdo it?
>
>
> Cheers

You might also want to cover gotchas like Python's references.

If you have the time I'd introduce weakref too.

[toc] | [prev] | [next] | [standalone]


#9411

FromTerry Reedy <tjreedy@udel.edu>
Date2011-07-13 12:29 -0400
Message-ID<mailman.996.1310574602.1164.python-list@python.org>
In reply to#9387
On 7/13/2011 8:39 AM, Anthony Kong wrote:

> I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work.
>
> <personal opinion>
> So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag  of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages.
> </personal opinion>
>
> I think I will go through the following items:
>
> itertools module

The iteration protocol and the notion of iteraables as the common data 
exchange format, with associated notions of iterators, generator 
functions, and generators, are important features of Python. Not really 
functional style, I guess.

> functools module
> concept of currying ('partial')
>
>
> I would therefore want to ask your input e.g.
>
> Is there any good example to illustrate the concept?
> What is the most important features you think I should cover?

Functions are first-class objects, like everything else.
Use of closures to create functions to be returned.


-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#9414

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-07-13 11:09 -0600
Message-ID<mailman.998.1310576988.1164.python-list@python.org>
In reply to#9387
On Wed, Jul 13, 2011 at 10:29 AM, Terry Reedy <tjreedy@udel.edu> wrote:
> The iteration protocol and the notion of iteraables as the common data
> exchange format, with associated notions of iterators, generator functions,
> and generators, are important features of Python. Not really functional
> style, I guess.

Xah Lee's assertion to the contrary notwithstanding, it seems to me
that list comprehensions are basically functional in style.  They are,
after all, equivalent to "map(f, filter(g, x))".

Iterators, on the other hand, by definition have the property that
each call to iter.next() has the side effect of changing the
iterator's state.  Therefore, although they can effectively be used as
a functional building block (e.g. by masking their use with a
comprehension), the iterators themselves are not actually functional.

[toc] | [prev] | [next] | [standalone]


#9458 — Re: Functional style programming in python: what will you talk about if you have an hour on this topic?

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2011-07-14 15:32 +1200
SubjectRe: Functional style programming in python: what will you talk about if you have an hour on this topic?
Message-ID<9876asF7v0U1@mid.individual.net>
In reply to#9387
Anthony Kong wrote:

> So I have picked this topic for one of my presentation. It is because
> functional programming technique is one of my favorite in my bag  of python trick.

I'm not sure it's a good idea to emphasise functional
programming too much. Python doesn't really lend itself
to a heavily functional style. While you *can* write
Python code that way, it's not idiomatic, and you're
likely to give beginners a distorted idea of how Python
is normally written.

-- 
Greg

[toc] | [prev] | [next] | [standalone]


#9459 — Re: Functional style programming in python: what will you talk about if you have an hour on this topic?

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2011-07-14 14:05 +1000
SubjectRe: Functional style programming in python: what will you talk about if you have an hour on this topic?
Message-ID<4e1e6b05$0$29973$c3e8da3$5496439d@news.astraweb.com>
In reply to#9458
On Thu, 14 Jul 2011 01:32 pm Gregory Ewing wrote:

> Anthony Kong wrote:
> 
>> So I have picked this topic for one of my presentation. It is because
>> functional programming technique is one of my favorite in my bag  of
>> python trick.
> 
> I'm not sure it's a good idea to emphasise functional
> programming too much. Python doesn't really lend itself
> to a heavily functional style. While you *can* write
> Python code that way, it's not idiomatic, and you're
> likely to give beginners a distorted idea of how Python
> is normally written.

I think that's true for *purely* functional code, but functional idioms are
very Pythonic. Iterators and generators, list comprehensions and generator
expressions, itertools, using functions as first-class objects (including
decorators) are all in a functional style. 

Python borrowed list comps from Haskell, just as it borrowed map from Lisp.
If you want to claim that map is "not Pythonic", I won't get into a fight
over it, but list comps certainly are!

I guess it really depends on how you wish to define "functional". To my
mind, even something as simple as "don't use global state, instead pass
arguments to functions as needed" is a Good Trick learned from functional
programming.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#9464

FromJonathan Hartley <tartley@tartley.com>
Date2011-07-14 03:33 -0700
Message-ID<a9c02a52-4587-45b3-88fa-19a2e2f8a8cd@r9g2000yql.googlegroups.com>
In reply to#9458
On Jul 14, 4:32 am, Gregory Ewing <greg.ew...@canterbury.ac.nz> wrote:
> Anthony Kong wrote:
> > So I have picked this topic for one of my presentation. It is because
> > functional programming technique is one of my favorite in my bag  of python trick.
>
> I'm not sure it's a good idea to emphasise functional
> programming too much. Python doesn't really lend itself
> to a heavily functional style. While you *can* write
> Python code that way, it's not idiomatic, and you're
> likely to give beginners a distorted idea of how Python
> is normally written.
>
> --
> Greg

Maybe the talk would work well if not aimed at complete all-round
beginners, but instead aimed at Pythonistas who are interested in
functional programming, or functionistas who are py-curious (I think
the same talk would work well for both groups)

[toc] | [prev] | [next] | [standalone]


#9463

FromJonathan Hartley <tartley@tartley.com>
Date2011-07-14 03:31 -0700
Message-ID<92cbf295-ece7-4bd1-8d65-a7ddcfbd8571@gc3g2000vbb.googlegroups.com>
In reply to#9387
On Jul 13, 1:39 pm, Anthony Kong <anthony.hw.k...@gmail.com> wrote:
> (My post did not appear in the mailing list, so this is my second try. Apology if it ends up posted twice)
>
> Hi, all,
>
> If you have read my previous posts to the group, you probably have some idea why I asked this question.
>
> I am giving a few presentations on python to my colleagues who are mainly java developers and starting to pick up python at work.
>
> <personal opinion>
> So I have picked this topic for one of my presentation. It is because functional programming technique is one of my favorite in my bag  of python trick. It also takes me to the rabbit hole of the functional programming world, which is vastly more interesting than the conventional procedural/OO languages.
> </personal opinion>
>
> I think I will go through the following items:
>
> itertools module
> functools module
> concept of currying ('partial')
>
> I would therefore want to ask your input e.g.
>
> Is there any good example to illustrate the concept?
> What is the most important features you think I should cover?
> What will happen if you overdo it?
>
> Cheers

I'd think you'd want to at least mention the relatively new
'lru_cache' decorator, for memoizing the return value expensive
functions, providing they are deterministic / pure, etc.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web