Member-only story
Type Annotations in Julia and Python
In Julia using type annotations is an integral part of writing Julia code. For Python however this is a fairly recent addition (version 3.5), which as of this writing (March 2019) has not been standardized. In Python they are referred to as type hints.
In Julia we would normally write a function incrementing an integer like this:
inc(a::Integer) = a + 1
This allows us to catch potential wrong usage of the function.
julia> inc(4)
5
julia> inc(nothing)
ERROR: MethodError: no method matching inc(::Nothing)
Closest candidates are:
inc(::Integer)
This has the benefit of catching the problem early on, where the function is called, rather than inside it. People doing C++ template programming will also be familiar with this problem. Type checking of generic types does not happen at the call site but inside the template function wherever the types don’t match up.
inc(a) = a + 1
Had I used this definition, the error would have been:
julia> inc(nothing)
ERROR: MethodError: no method matching +(::Nothing, ::Int64)
Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...) at operators.jl:502
+(::Complex{Bool}, ::Real) at complex.jl:292
+(::Missing, ::Number) at missing.jl:93
So what we are seeing is that Julia is complaining about not finding a function call to satisfy nothing + 1