[Tutor] Python best practices
Lie Ryan
lie.1296 at gmail.com
Mon Nov 30 06:42:28 CET 2009
On 11/29/2009 8:59 PM, spir wrote:
> Lie Ryan<lie.1296 at gmail.com> dixit:
>
>>> - functions should return one value (im not 100% of this one)
>>
>> I 100% disagree or with this one.
>
> Could you explain this bit, Lie? I'm very interested.
> I use multiple-value result myself, for it's so practicle in given
> cases. But it makes me uneasy; also have the impression (why?) it
> reveals wrong design.
I guess this particular "advice" comes from languages like C/C++ where
returning a struct means copying the whole struct, which could be a very
expensive. In python, returning tuple is cheap; it's just copying
references. Don't hesitate to return multiple values, whenever it is
meaningful/useful (either tuple or list or dict or ...).
More information about the Tutor
mailing list