It is common that programming languages have different types with similar or analogous functionality. For example, consider the integer types Int64
, BigInt
, or the float point types Float64
, BigFloat
.
The reason for this proriferation of types is that none of them is adequate for every situation. Int64
is favored when one needs high speed of execution, whereas BigInt
is favored when one is doing calculations with very big numbers.
Given that for some users, the Big
types might be more adequate than the 64
types, why not let the user decide which one of them is Julia’s default?
The kinds of calculations that I do are so small, that I actually have the luxury of not worrying so much about efficiency. In my case, the BigInt
type is much more convenient for me than the Int64
type, because using the first I do not have to check for integer overflow.
But the only way I have of writting Julia code with the Big
types in place of the 64
types is either to use the big"-"
or syntax everywhere, or to start every line of code with some macro. A trivial arithmetical operation julia> 157 + 82
would become julia> big"157" + big"82"
or julia> @MyMacro 157 + 82
.
I have some arguments for letting the users change the default types:
- It seems that many programmer prefer big integers over 64 bits integers.
This might be inferred from the fact that some popular languages (among them Python, JavaScript, Haskell, Ruby) chose big integers as their default.
- There are languages that allow users to change the default type.
At least Haskell does this: Kwang's Haskell Blog - Type defaulting in Haskell
- Letting users change the default type fits very well with the philosophy and design of the Julia Language, as I understood it.Ju
Julia tries not to privilege it’s built-in types, and gives the user the flexibility to use his own custom type. In Julia we have numbers with measurement units(Unitful.jl), dual number(DualNumbers.jl), doublefloats(DoubleFloats.jl), and those numbers are just as good and efficient as the built-in numbers - something that is unimaginable in other languages.