[Python-3000] Nix dict.copy()

Adam Olsen rhamph at gmail.com
Sun Feb 10 22:39:22 CET 2008


On Feb 10, 2008 1:49 PM, Christian Heimes <lists at cheimes.de> wrote:
> Larry Hastings wrote:
> > +1 for exactly the reasons cited.  I think copy() and deepcopy() should
> > both be "essential" built-in functions.
>
> I'm -0 on copy and -1 on deepcopy.
>
> If you need a copy or a deepcopy of an object (except dicts, lists and
> sets) you are most certainly using the wrong approach. Back when I was
> learning Python over 5 years ago I was using copy and deepcopy often.
> Nowadays I don't need the copy module anymore because I've learned how
> to design software without the need for copies.
>
> In my humble opinion the addition of copy to builtins leaves a bad mark.

-1 on both.

If a dict is wrong for some input, it's probably wrong for all inputs.
 If you're keeping this new dict for your own uses then you clearly
want to keep it as your preferred type, and if you're returning it to
your caller the preference for builtins is clearly want a single
standardized return type (even filter does this in 3.0).

I'm having a hard time imagining cases where you *really* want to
return a copy of whatever the original type was, and this makes me
think we shouldn't encourage that coding style.

dict(iterable) for the one, and only one, obvious way to do it.

-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list