Appending to []
Bernd Nawothnig
Bernd.Nawothnig at t-online.de
Sat Apr 21 11:41:03 EDT 2012
On 2012-04-21, Kiuhnm wrote:
>> Returning a None-value is pretty useless. Why not returning self, which would be
>> the resulting list in this case? Returning self would make the
>> language a little bit more functional, without any drawback.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>
>> Then nested calls like
>>
>> a = [].append('x').append('y').append('z')
>
> You just answered to your own question: append returns None so that
> people can't use it the way you did.
That is one possible way to design the method, but not the only
possible way.
> You make the reader believe that you're adhering to the functional
> paradigm whereas 'append' has actually side effects!
> Moreover, you use an assignment just to reinforce this wrong belief.
I know about side effects and I know that letting append return self
would not make Python a purely functional language with only immutable
data.
I just asked a simple question about a detail I personally would
consider it to be useful.
Please no further religious war about that ;-)
Bernd
--
"Die Antisemiten vergeben es den Juden nicht, dass die Juden Geist
haben - und Geld." [Friedrich Nietzsche]
More information about the Python-list
mailing list