Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Apr 6 12:52:21 EDT 2014
On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote:
> Mark H Harris <harrismh777 at gmail.com>:
>
>> On 4/4/14 4:53 AM, Steven D'Aprano wrote:
>>> Python is not a computer-science-ey language.
>>
>> Every programming language is interesting from a comp sci standpoint.
>> Some are more useful for research; python is one of those.
>>
>> For what reasons do you disagree?
>
> Computer science doesn't mean "anything related to computers."
> Physicists typically couldn't care less about your heating up your lunch
> in the microwave oven. Similarly, computer scientists aren't interested
> in the mundane applications of their lofty research topics.
>
> Python, BTW, is perfectly suitable for computer science.
I don't think it is. Python is not a pure functional language, so it's
very difficult to prove anything about the code apart from running it.
For example, see Brett Cannon's master's thesis, where he essentially
demonstrates that:
- you can't do compile-time type inference of general types in Python;
- although you can infer a very small amount of information about a
few built-in types;
- adding specialized byte-codes to handle those types gives, at best,
a marginal performance boost, and sometimes even slows code down.
To quote from the conclusion:
"Introducing over 3,000 lines of new C code to Python’s compiler
to get, at best, a 1% improvement is in no way justified. The
level of added complexity that would be introduced into the
compilation step would definitely need to lead to a noticeable
performance improvement, the 5% that was the goal, to justify the
cost of code maintenance."
http://citeseerx.ist.psu.edu/viewdoc/download?
doi=10.1.1.90.3231&rep=rep1&type=pdf
What does it mean to say that a language like Python is suitable for use
in computer science? It can mean (at least) four things:
(1) If you do an undergraduate computer science course, they will teach
you Python.
While this is good for the general Python community, it's hardly *doing*
computer science. It's *learning* computer science. (I read a book by
Richard Dawkins. That doesn't mean I'm a biologist.) So while I agree
that it is significant that some universities will teach Python to
undergraduates, I don't count this as Python being used in computer
science. I think we need to look at postgraduate use of Python, not
undergraduate.
(2) Some post-grads use Python as a tool, e.g. they use a Python script
to analyse some data. In this case, the use of Python is incidental to
the research they are doing. They might have used Perl, or a bash script,
or calculated the results by hand. In a similar fashion, they probably
wrote up their results using Microsoft Word. It's just a tool.
(3) Some post-grads do original research *into* Python, as a language.
Brett Cannon's thesis is proof that this has happened at least once.
I think this does count as doing computer science with Python, although
only marginally. No slight intended, but it should be obvious that
something like Brett's thesis has very little application outside of
Python itself. Perhaps a little: if there is another language with
similar types of dynamism as Python, you might conclude that it too is
not a good candidate for compile-time type inference.
(4) This is the category which I was referring to when I said that Python
wasn't a "computer-science-ey language": do people use Python for
research into language-independent fundamental principles of computation?
I don't think so. I agree with Marko that normally you:
> you either use a pseudolanguage or some sort of formalism that
> hasn't been implemented.
E.g. most of the really deep stuff by Turing wasn't even performed on a
computer, since there were no computers[1], or languages to program them
in. A lot (all?) of Knuth's published work is written in an assembly
language for an imaginary processor. Douglas Hofstadter invented two
languages, BlooP and FlooP, to demonstrate the difference between
programming languages that are, or aren't, Turing complete. (He also
named a mythical super-Turing language GlooP.)
Some languages are better suited for academic research of this nature.
Python is too... messy, I suppose. Python's mix of imperative, functional
and OOP paradigms makes it really useful for solving problems, but less
useful for academic research of this type, where pure functional, pure
OOP paradigms are more useful. Naturally I'm not saying that there is
*absolutely no* comp-sci work done using Python, that would be foolish,
only that it is in a minority and is not well-suited for the sort of
problems academics are interested in.
But since I'm not a computer scientist, perhaps I'm wrong. Anyone have
any studies showing what percentage of research papers use various
languages?
> In theoretical computer science, they cherish off-the-wall models that
> detach the topic from everyday applications. Here are examples that I
> remember from graduate school:
>
> * combinatory birds in forests
I don't believe that came from academia. If I've understood correctly,
that was from a non-academic book on applying the lambda calculus to
solve practical applications.
> * unfaithful husbands on an island ruled by female logicians
I don't know that one.
> * dining philosophers getting into a deadlock over forks
>
> * Byzantine generals trying to agree on a surprise onslaught on a
> besieged city
[1] Actually there were. They were women who had the tedious job of
performing large numbers of tedious computations by hand. But there were
no *electronic* computers.
--
Steven D'Aprano
http://import-that.dreamwidth.org/
More information about the Python-list
mailing list