3 ms·
There are some people that are saying not allowing Number and Integer to mix is error prone, but I don't really see it. For example, in Ruby if you do a calcula
by yladiz 9y ago
There are some people that are saying not allowing Number and Integer to mix is error prone, but I don't really see it. For example, in Ruby if you do a calculation that's large enough, it just becomes a Bignum [1]. The easiest way to handle this would probably be to just allow arbitrarily large numbers, and if it overflows beyond the Number, turn it into a Integer automatically (and vice versa, if it becomes smaller than a Integer, turn it into a Number). In Ruby, the Bignum and Fixnum apis are also the same, with only the internal representation, as well as a few specific differences in how you handle a Bignum, as differences.
I can kind of understand the FAQ section about it, since JavaScript in the browser has to be backwards compatible, but are there really that many applications that depend on Integers acting like they do now at such high values that just transforming them into Numbers won't suffice? The only difference would be for bitwise operations, which are primarily used in Node, and you can explicitly document that change in a major version update, unlike in a browser.
Also, nitpick: Why not just call it BigNumber, or at least BigInteger? Integer as the name of an arbitrarily large number is going to be confusing.
Edit: newer Ruby versions treat Bignum and Fixnum as just Integer (since it was mainly an implementation detail), but my argument is still the same.
1: http://ruby-doc.org/core-2.2.0/Bignum.html http://ruby-doc.org/core-2.2.0/Bignum.html
- dragonwriter 9y ago> In Ruby, the Bignum and Fixnum apis are also the same, with only the internal representation, as well as a few specific differences in how you handle a Bignum, as differences. In current Ruby, "Fixnum" and "Bignum" are legacy-support aliases for the unified "Integer" class. http://blog.bigbinary.com/2016/11/18/ruby-2-4-unifies-fixnum-and-bignum-into-integer.html http://blog.bigbinary.com/2016/11/18/ruby-2-4-unifies-fixnum... > Integer as the name of an arbitrarily large number is going to be confusing. "Integer" in mathematics is the name of an class of numbers that is unbounded on both the high and low end; it is using "Integer" as the name of a restricted range that is counterintuitive.
- yladiz 9y agoThe argument is still the same, now the user facing aspect is hidden (I don't know the Ruby source code, but I would guess they just rewrote the external facing code so the user doesn't have to care about Bignum or Fixnum, and just care about a single Integer). As to your second point, why not just move everything to Number then and if it needs a decimal point, treat it as a floating point value? I argued in the original post that there can't be that many applications that depend on the current implementation, and those that do purposefully can be rewritten. Edit: Integer -> Number
- dragonwriter 9y ago> The argument is still the same, now the user facing aspect is hidden Well, the language has changed so that they are unified. The underlying implementation may use different representations at different sizes, and presumably CRuby still uses the same internal split that the language exposed externally, at least for now. > As to your second point, why not just move everything to Integer then? Because not all numbers are integers, so you still need JS's number type (limited range and precision reals) if you have arbitrary precision integers.