3 ms·
One of my favourite things about Python is that its integers are true integers: they do not overflow or wrap. In my opinion, this is the correct default for mos
by joppy 6y ago
One of my favourite things about Python is that its integers are true integers: they do not overflow or wrap. In my opinion, this is the correct default for most programming languages (in fact, I would have gone a step further and made integer division return fractions rather than floats by default, as well). It removes so many problems (especially for beginners) since it is the way that integers work in the real world: for example x + 1 > x always, with no exceptions.
Of course for efficiency concerns, programmers should have access to fixed-width integers as well, but I think that true integers should be the default. It was also contemplated for Go [1], and was pointed out that true integers benefit from being a core language feature, since the compiler can perform a lot of SMI (SMall Integer) optimisations, which essentially use machine integers for small enough integers, before switching to a more complicated implementation. They also recognise that the biggest benefit to a bigint type is making it the default integer type.
[1]: https://github.com/golang/go/issues/19623 https://github.com/golang/go/issues/19623
- duckerude 6y ago> in fact, I would have gone a step further and made integer division return fractions rather than floats by default, as well This was decided against in Python: > ABC had two types of numbers at run time; exact numbers which were represented as arbitrary precision rational numbers and approximate numbers which were represented as binary floating point with extended exponent range. The rational numbers didn’t pan out in my view. (Anecdote: I tried to compute my taxes once using ABC. The program, which seemed fairly straightforward, was taking way too long to compute a few simple numbers. Upon investigation it turned out that it was doing arithmetic on numers with thousands of digits of precision, which were to be rounded to guilders and cents for printing.) https://python-history.blogspot.com/2009/02/early-language-design-and-development.html https://python-history.blogspot.com/2009/02/early-language-d...