[Python-ideas] Deprecate the round builtin

Steven D'Aprano steve at pearwood.info
Thu Sep 27 04:15:41 CEST 2012


On 27/09/12 11:14, Calvin Spealman wrote:
> On Wed, Sep 26, 2012 at 2:55 PM, Guido van Rossum<guido at python.org>  wrote:
>> On Wed, Sep 26, 2012 at 11:51 AM, Mike Graham<mikegraham at gmail.com>  wrote:
>>> The builtin round function is completely useless. I've never seen
>>> anyone use it constructively. Usually people using it are new
>>> programmers who are not comfortable with or aware of string
>>> formatting. Sometimes people use it to poorly replicate functionality
>>> that's implemented correctly in the decimal module.
>>
>> You're probably right. It has ancient ancestry: it was one of the
>> functions I copied directly from ABC. (It's actually more useful now
>> that floats are printed with minimal digits.)
>>
>> But given the pain of removing a builtin, is it worth it? maybe we can
>> just document the better ways of accomplishing its tasks?
>
> I think it is reasonable with the right justifications, deprecation period, and
> obvious migration path.
>
> Also, I'd be completely in support of dropping round() and agree it gets misused
> and leads to too much confusion. We should promote the right ways, and some
> times to show the right path you need to lock another door and throw
> away the key.


I don't believe that round gets misused and causes confusion to any significant
degree. That belief is based on many years experience on two high-traffic mailing
lists with many beginners. I've seen plenty of examples of beginners confused that
Python can't add floats correctly, but if I've ever seen somebody confused by round,
it was so uncommon and so long ago I've forgotten it.

It seems to me that this proposal is based on a purely theoretical fear that some
people manage to escape being confused by the far more obvious floating point
gotchas[1] but can't understand round. There are much more common, and bigger,
surprises with binary floats than round, and it seems to me that depreciating it
just disrupts those who do use it for no real benefit.

So -1 on such a change.

I could be convinced to change that to a -0.5 if round were moved to the math module
exactly as is, including the second argument. But even that is a disruption for no
meaningful benefit.



[1] I managed to surprise myself the other week when I "discovered" what was obvious
in hindsight, that for sufficiently large values all finite floats are even integer
values. I had known the "integer value" part, but was surprised by the "even" part.
I shouldn't have been.


-- 
Steven



More information about the Python-ideas mailing list