[Python-Dev] Cleaning-up the new unittest API

Michael Foord fuzzyman at voidspace.org.uk
Tue Nov 2 17:29:36 CET 2010


On 02/11/2010 16:23, Terry Reedy wrote:
> On 11/2/2010 10:05 AM, C. Titus Brown wrote:
>
>> ...but, as someone who has to figure out how to teach stuff to CSE 
>> undergrads
>> (and biology grads) I hate the statement "...any programmer should
>> expect this..."
>
> And indeed I (intentionally) did not say that. People who are ignorant 
> and inexperienced about something should avoid making expectations in 
> any direction until they have read the doc and experimented a bit.
Expectations come from consistent behaviour. sorted behaves consistently 
for *most* of the built-in types and will also work for custom types 
that provide a 'standard' (total ordering) implementation of __lt__.

It is very easy to *not realise* that a consequence of sets (and 
frozensets) providing partial ordering through operator overloading is 
that sorting is undefined for them. Particularly as it still works for 
other mutable collections. Worth being aware that custom implementations 
of standard operators will break expectations of users who aren't 
intimately aware of the problem domains that the specific type may be 
created for.

All the best,

Michael Foord

>
> What I did say in the post you responded to is "Any programmer who 
> sorts (or uses functions that depend on proper sorting) should know 
> and respect the difference between partial orders, such as set 
> inclusion, and total orders, such as lex order of sequences." I should 
> hope that you teach the difference, or rather, help students to notice 
> what they already know. Tell them to consider that difference between 
> sorting people by a totally ordered characteristic like height or 
> weight and a characteristic that is at best partially ordered, like 
> hair color or ethical character. Or have them consider the partial 
> order dependencies between morning get-ready-for-class activities 
> (socks before shoes versus pants and shirt in either order). They 
> already do topological sorting every day, even if the name seems fancy.
>


-- 
http://www.voidspace.org.uk/



More information about the Python-Dev mailing list