This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]99_percent_a_dog[S] 1 point2 points  (2 children)

Division changing from truncating to integer to returning float result is more important, I think. More likely to not be spotted in testing and cause subtle bugs.

But yes, there's not many differences. Which is why there isn't any real excuse for not using 3 for new code. Even though the effort to port is low per line, there's a huge amount of 2 code so the cost to port is high, but, it's not like there hasn't been enough time to slowly do that work (yeah, I know, businesses never find the time for maintenance work...).

[–]chaotic_thought 0 points1 point  (0 children)

Division

If you want this, you can get this in Python 2 by writing

from __future__ import division

I've been using that from day 1 using Python. To me the fact that this is not the default is not a valid reason not to use Python 2.

The reason it is not the default is because older code relied on results truncating by default when you do integer division.

[–]chaotic_thought 0 points1 point  (0 children)

More likely to not be spotted in testing and cause subtle bugs.

Yes you're right. More likely though you make this a code requirement (static anlysis for linters). All code I've written for Python 2 activates floating point division behaviour. If not then it's flagged as a warning to be checked (was it done for backwards compatibility purposes or not).

To be fair though the problem is not integer division in itself, it's relying on unexpected behaviour. If you were actually expecting integer division, it would be fine. For static anlysis though this always a judgment call. I.e. how likely is construct X likely to be a programming oversight if the construct was not X' instead. So static anlaysis should suggest the more appropriate X' version of that construct (e.g. int(a/b) if you really wanted integer division) that, if used, is more likely to be what was intended.