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

BartC bc at freeuk.com
Wed Nov 25 07:35:32 EST 2015


On 25/11/2015 08:32, Chris Angelico wrote:
> On Wed, Nov 25, 2015 at 7:14 PM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> What exactly is your point? People's confusions don't disappear
>> because you as an expert have a good understanding of what is
>> going on and so are no longer confused.
>>
>> Some aspects in the langauage are easily grasped and other
>> aspects tend to create confusion. I see nothing wrong with
>> people trying to point out what the cause of this confusion
>> could be. You arguing that people shouldn't be confused is
>> not helping.
>
> "Oh come on. It's basic arithmetic. You should be able to add 7 and
> 7... the result's 14!"
>
> "But it's so confusing. Why can't it be 16? It'd be more convenient
> for me if it were 16."
>
> "This is just how arithmetic works."
>
> "But it's still confusing!"
>
> At some point, you have to simply accept that this is how the system
> works.. or use a different system. (Octal maybe.) If you are
> perpetually confused by Python, you need to either learn how Python
> works, or use something else.

What is the purpose of the language, to make things easier for people or 
what? And who is it for?

In other forums I've frequently recommended Python as an easy to learn 
language with a rapid development cycle. That was before I knew it had 
nearly as many quirks and gotchas as C!

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. (Eg Lisp, which has at least 4 
different ways of comparing for equality. Python only has two that I 
know of. A simple language would have only one, although my own has 
recently graduated from one to two; it's no longer simple!)

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.

OK, so both names are bound to the same object-value. So then you try this:

a = 10
b = a
b += 1

'+=' is an 'in-place add', so you might expect different semantics from 
'b = b+1'. But no, a isn't changed (disappointingly!).

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.

OK, but now I have to continuously think about whether this 
multiple-set-of-objects is going to be a tuple or a list, or something 
else entirely (my date example above I think needs to be a class in 
Python, so that's a third way of doing things. Plus there is something 
called a 'set' that I haven't played with yet).

 > or use something else.

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?

-- 
Bartc



More information about the Python-list mailing list