I guess it’s that I’ve found Julia to require me to be EXACT when it comes to data types. If I have a method:
function foobar(a::Int32)
end
foobar(0)
That results in a compiler error, I’m assuming because I wasn’t exact. Nevermind that there is only one foobar method defined. Constants are Ints (or maybe Int64s) and the compiler will not automatically change the data type of a static. I must be EXACT in my data type declarations, no assumptions will be made.
This “side effect” I really love:
function foobar(b::Int, a::Int32 = 0)
end
foobar(4)
ERROR: LoadError: MethodError: no method matching foobar(::Int64, ::Int64)
Closest candidates are:
foobar(::Int64, ::Int32) at /home/pixel/test.jl:2
foobar(::Int64) at /home/pixel/test.jl:2
Fine, I accept that, all my constants are wrapped in their data types.
Likewise data type conversions must be exact, if they can’t been done exactly an exception is thrown (not a compiler error but still drastic). I needed to do bit twiddling on numeric values, so I needed to treat signed values as unsigned. I was required to use reinterpret()
for that change…again I needed to be exact in what I wanted to happen, no assumptions!
Again I’ve accepted I must be exact, it’s a good thing, it ensures I tell the compiler EXACTLY what I’m doing.
Then there are comparisons…oh THERE you don’t need to be exact because, because…because I don’t know why.
julia> 5 == 5.0
true
julia> UInt(5) == -5.5
false
Here however, 5 == 5.0
automatic conversion, I guess it was a safe conversion? And UInt(5) == -5.5
is false not because the values are different but because a common type cannot be found for both types…I guess? Okay so where is the exactness that I’m required everywhere else?
And if safe conversions happen automatically then why not here?
function foobar(b::Int64, a::Int128 = 0)
end
foobar(4)
ERROR: LoadError: MethodError: no method matching foobar(::Int64, ::Int64)
Closest candidates are:
foobar(::Int64, ::Int128) at /home/pixel/test.jl:2
foobar(::Int64) at /home/pixel/test.jl:2
Wouldn’t an automatic conversion from Int64 to Int128 be safe?
I guess I just assumed I needed to be exact to avoid unintentional programming errors. Yet comparing values of different types I don’t need to be exact…I can be as sloppy as I like?