why python annoys me
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Sat Apr 21 17:43:56 EDT 2001
Sat, 21 Apr 2001 11:30:54 -0700, James Logajan <JamesL at Lugoj.Com> pisze:
> what are (or is?) "list comprehensions"?
A syntax which looks for example like this in Python:
[x+y for x in l1 if x<0 for y in f(x)]
which means:
__result = []
for x in l1:
if x<0:
for y in f(x):
__result.append(x+y)
# Result is in the variable __result
except that it's a single expression (and doesn't create the variable
named __result).
> definition of "functional programming"?
IMHO the most important technical aspects are:
1. working with immutable data,
2. working with functions as values.
In the resulting style implicit maintaining of mutable state is
avoided, dependencies on inputs and produced outputs are more explicit,
recursion is preferred to loops, expressions are more important than
statements, values of expressions rarely depend on the moment of
evaluation, reading inputs is often separated from processing the
data in internal forms and from writing outputs, functions taking
functions as arguments often replace control structures, behaviors
are expressed as data, examining object values is more important than
checking object identities, effect of an operation is expressed as
returning appropriately structured data instead of setting variables
or raising exceptions, nesting of simple structures is preferred to
big flat objects, objects are more often put into structures which
define relationships with other objects than maintain relationships
themselves...
I'm afraid it's hard to explain.
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK
More information about the Python-list
mailing list