Message243485
Conceptually there's a distinction between the two cases, but you can implement one in terms of the other, so I don't think it's worth adding two functions/macros here. So let's pick the better API.
"Py_cmp_to_bool" is better if you already have a cmp-style result. Python code is full of cmp-style results, but I think a big reason is that py2 required them, and (rightly) nobody wants to rewrite the algorithms. I believe the py3 way of passing in the operator is better API.
I've seen (a - b) far too many times, which gives the right result in most but *not all* cases. (Think small floats where the difference is coerced to int for the Py_cmp_to_bool function. Or int overflow.)
The correct ways to get a cmp-style result are "(a > b) - (a < b)" or "(a < b) ? -1 : (a > b)". Do we want to add a function that requires you to write, read, and understand that? |
|
Date |
User |
Action |
Args |
2015-05-18 14:55:56 | petr.viktorin | set | recipients:
+ petr.viktorin, lemburg, barry, rhettinger, skrah, ethan.furman, serhiy.storchaka |
2015-05-18 14:55:56 | petr.viktorin | set | messageid: <1431960956.09.0.552237141293.issue23699@psf.upfronthosting.co.za> |
2015-05-18 14:55:56 | petr.viktorin | link | issue23699 messages |
2015-05-18 14:55:55 | petr.viktorin | create | |
|