Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Marko Rauhamaa marko at pacujo.net
Wed Nov 25 08:06:04 EST 2015


BartC <bc at freeuk.com>:

> That was in preference to other choices which I found difficult and
> also elitist because of the advanced knowledge of CS and mathematics
> that it seemed you were expected to know.

Python is not a toy. It is a tool for advanced programmers.

Mathematics has barely any touching point, but yes, solid CS fluency is
required to be a productive software developer regardless of the
programming language.

Is a plumber an elitist, when he prefers to use tools I wouldn't know
how to operate?

> One gotcha at least is well known. Where, in a language of the least
> surprises, you might write:
>
>  d1 = date (25,12,2010)
>  d2 = d1
>  d2.year += 1
>
> You would expect d1 and d2 to represent a period one year apart. In
> Python, they would both be the later date.

No elitism or expertise would help you "expect" any outcome. I wouldn't
even expect d2 to have a field called "year". That's why you read the
specification.

> Then, from the point of view of a beginner, you have two distinct ways
> of representing a list of objects: a tuple and a list. Exactly why
> there have to be two is never really made clear beyond the inadequate
> explanation that one is immutable and the other mutable.

>From a functional point of view, there don't have to be two separate
concepts. The immutability of tuples is also just a design choice.

However, tuples are a way to represent records, groupings of related
values, where the semantics of each value is determined by its position
in the tuple. The members in a tuple are typically of different data
types.

Lists are collections of values. Typically, each member of list is of
the same type.

Tuples are handy because they allow you to treat multiple values as a
single value. Also, they are syntactically analogous to tuples in
mathematics so chances are you have encountered them in elementary
school. Finally, they are similar to function arguments, allowing you to
return multiple values the same way you pass multiple values to the
function.

> Python isn't as bad as some languages, but it's well on the way. But
> is there anything simpler around that is also well-supported?

My "simpler" is different from your "simpler". Even C# has a lot of
advanced concepts, as maybe even Fortran does nowadays.

My own recommendation would be Scheme, but it is even more "elitist"
than Python.


Marko



More information about the Python-list mailing list