Thought on PEP 204 and 276

Steve Holden sholden at holdenweb.com
Tue Jun 4 16:57:00 EDT 2002


"Stephen Horne" <steve at lurking.demon.co.uk> wrote ...
> On Tue, 4 Jun 2002 10:49:19 -0400, "Steve Holden"
> <sholden at holdenweb.com> wrote:
>
> >"phil hunt" <philh at comuno.freeserve.co.uk> wrote in message
> >news:slrnaf7mo4.dfe.philh at comuno.freeserve.co.uk...
>
> >> I think they are essentially the same. A sequence tpye is just a
> >> mapping type where the keys are restricted to the integers from
> >> 0 to however many elements there are minus 1.
> >>
> >No matter what you think, they are essentially different. Insertion into
a
> >mapping doesn't alter the key to which other elements are mapped, but
> >insertion into a sequence (potentially) does that.
>
> What is normally referred to as insertion in dictionaries is actually
> more like overwriting a list element. This is why handling both with
> the 'container [key] = value' syntax is natural.
>
aarrgghh. So we can completely ignore the fact that the len() of a
dictionary will change after an insertion while the len() of a list won't
after an element is overwritten?

> Insertion with modification of existing keys to make room (ie list
> insertion) simply does not exist in lists. The usefulness of list
> insertion derives from the fact that a list is a very specialised type
> of key-to-value mapping - in this respect, the type 'list' should
> clearly inheret from and extend the more general key-to-value type
> called a dictionary.
>
It might be clear to you. It certainly isn't to me. I believe you are
looking to unify two fundamentally different semantics.

Neither does it make sense in implementation terms. List insertion's
usefulness is in fact limited to situations where performance isn't unduly
degraded by the need to modify the representation too radically. Of course,
where performance doesn't matter, it doesn't matter.

> In essence, you are confusing the operations on the underlying data
> structures with the operations on the conceptual types. These are two
> separate concepts. The implementation is distinct from the
> user-visible abstraction.
>
Fine. You write your programs to delete lists element-by-element from the
front, and don't complain about performance -- that's just an aspect of the
implementation.

While I admire your attempt to maintain theoretical purity here, Python is a
pragmatist's language. I don't think I'll be bothering to conceptualise
dictionary insertion as overwriting a non-existent element, thank you very
much.

pragmatical-ly y'rs  - steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------









More information about the Python-list mailing list