Why I hate lambdas (Re: Do any of you recommend Python as a firstprogramming language?)

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Mar 24 11:52:59 EDT 2008


Paul Rubin>It's at least pretty good.  It's not ideal, but nothing
ever is.<

I agree. At the moment Python is among the best languages for that,
but it's not perfect for that purpose. I think newbies may need a bit
more structured language, where you have to put things in a certain
order to have a working program. I think this may teach them some good
programming habits. Pascal is a bit too much old today, but it helps
learn how to program in a tidy way. I am not sure about this, I'd like
to have more data to be able to sort out this freedom/structure
alternative regarding teaching languages.
Another possible downside of Python is that it doesn't allow you to
know very well what's under the language, so you can't use pointers
and memory very well, so you can't learn those things very well. You
need a different language for that, like C (or Pascal) or assembly,
but such languages are useful later, and less as very first languages,
especially for very young people.


Paul Rubin>Chris Okasaki (of functional data structures fame) has an
interesting blog post about why indentation-based structuring is a big
help for teaching:<

I have quite appreciated that article, and other people are doing
similar things for C and C++ (I'd like to do something similar for D):
http://blog.micropledge.com/2007/09/nobraces/
And OCaml:
http://people.csail.mit.edu/mikelin/ocaml+twt/


Arnaud Delobelle>My other 'coming of age' was when I took a lambda-
calculus course at university.  I felt like a man who's had a black
and white TV set all his life and watches colour TV for the first
time.<

Scheme-like languages are surely interesting, and eventually a
programmer can learn one of them, but I think as a very first language
Python is fitter, because its syntax is more compatible with a normal
little trained human mind.



7stud>Beginning programmers in grades 9-12 are not going to understand
issues like that, and it would be a mistake to try and introduce
them.  Beginning programmers should be concentrating their efforts on
learning the syntax of a language and basic constructs like for-loops
and if statements.<

This is wrong. Some languages like Scheme are quite fit for young
people, and they don't even need a for loop. A 7-9 years old person is
able to understand quite a lot, and computer science and programming
aren't based on syntax. They are more based on the fun of problem
solving, and similar things. Syntax is important because it's the tool
that allows you to tell the computer how to compute the results of the
problems you have (usually) already solved, but it can't be the
purpose, even in a first course of programming. When you want to teach
painting to a 6 year old child your purpose isn't teaching her/him all
about the structure of the canvas and brushes and the chemistry of the
pigments, but how to have fun putting all the colors on the canvas/
paper, trying to create some image, for fun. (On the other hand you
can teach to love chemistry to a 6-8 year old person, showing how much
it can be fun, if you start talking about the chemistry behind the
colors of fireworks, but that's not panting anymore).


Ben C>Why does Python not have a switch or until statement?<

Maybe because it thinks syntax minimalism is a virtue, or maybe
because they aren't easy to add (try to design a do-while using Python-
like syntax).


Ben C>Why are very common objects (stack, queue, linked list) not
builtin? etc.<

Because it was a small language, used for scripting purposes, I think.
You need those data structures if you want higher performance (in
speed and/or memory used) but performance was not one of the main
purposes of Python.
Another purpose for those data structures is to teach them, but a good
teaching language is probably one that allows you to write your own
versions of them.
Today the collections module and other built-in modules gives you some
of those data structures, you just need to import them, so using them
isn't much a hassle, even if they aren't built in.


Aahz>The problem with lambda is that too often it results in clutter<

Probably I am missing your point, but I'd like to remind people the
syntax for lambdas in the last C# versions:
x, y => x * 2 + y
Instead of the Python syntax:
lambda x, y: x * 2 + y
I think that C# syntax is nice and readable enough.


Terry Reedy>[lot of things] Yes, fundamentally different categories of
types are (sensibly) treated differently with repect to definition and
namespace names, but calling that 'disharmony' depends on the
listener.<

Thank you for your interesting explanation.

Bye,
bearophile



More information about the Python-list mailing list