Why return None?

Mel Wilson mwilson at the-wire.com
Wed Aug 25 16:50:15 CEST 2004

In article <dave.opstad-E72D18.07305325082004 at reader0903.news.uu.net>,
Dave Opstad <dave.opstad at agfamonotype.com> wrote:
>In article <412c6edb$0$258$edfadb0f at dread12.news.tele.dk>,
> Max M <maxm at mxm.dk> wrote:
>> That the sort() method returns a None is actually a pedagocical tool to
>> tell the programmer that the list is modified in place.
>> If it had returned the list the programmer would later be surprised to
>> find that the list had been modified. It would seem like hard to find
>> nasty side effect. The way it is now is very explicit and easy to find out.
>But isn't the fact that the list is modified in place incidental to the
>fact of sorting? One is an implementation detail, and the other is the
>semantic meaning you're trying to express.

   It's not incidental to the fact that the original list is
"destroyed" by the sorting operation.

        Regards.        Mel.

More information about the Python-list mailing list