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

BartC bc at freeuk.com
Wed Nov 25 09:34:12 EST 2015


On 25/11/2015 13:53, Marko Rauhamaa wrote:
> BartC <bc at freeuk.com>:
>
>> Using tuples in the same way that other languages implement records is
>> going to be difficult if you can't change the values of the fields!
>
> Guido could decide tomorrow that tuples are mutable.

(Could that be done without breaking existing code? And what then would 
be the difference between them and lists?)

> Anyway, Python has two ways to represent records: classes and tuples.
> Tuples are nice because they are concise and ad hoc. Often you start
> with a scalar value, then turn it into a tuple. After a while your handy
> tuple turns out a bit cumbersome to use so you convert it into an actual
> class.

This is how records are handled in another language which I believe is 
simpler than Python: http://pastebin.com/vhsJML8U

This also implements my example from earlier in the thread. Now compare 
with Python's approach.

OK, that also needs two concepts, a list, and a record. But the 
distinction is now completely obvious. Records are also mutable. It 
would also be clear why you can't append to a record.

Now try explaining again to me how you would use tuples for the same 
thing...

-- 
Bartc



More information about the Python-list mailing list