by threw4234324 · 6y ago · 0 comments
If you're in a field where symbols have existing meanings, it's asinine to make your code clunky and harder to read by not using those existing meanings.
Python is my main language, and I struggled mightily to get my head around some aspects of Swift (e.g. randomly sticking question marks in different places until it was happy). As an aside, I also found the API incredibly verbose, the documentation poor, and Xcode to be a bad IDE.
In contrast, I enjoyed Julia - while the documentation isn't great either, after a single afternoon of learning (with plenty of Googling) I was able to port code over from Python and have it run perfectly.
That said, for machine learning a static type system (as they are now) is definitely not as much of a boom as in most other areas. Most of it involves tensor operations, and embedding things like it's shape in the generics will often lead to an exponential explosion of possible monomorphizations that the compiler will be forced to create. Even JIT languages like Julia will have trouble even though it only needs to compile when it's used (for example StaticArrays will get to a point when the compiler will take so much time that it's not worth it anymore). And even then I feel like most of the issues that actually take time are deeper than stuff like shapes and not naming dimensions, like numerical instabilities, hyperparameter tuning, architecture search and other stuff that gets more benefit of a language allowing quicker exploration.
julia> foo(x) = x^2 - 2x + factorial(4x)
foo (generic function with 1 method)
julia> @code_typed foo(4)
CodeInfo(
1 ─ %1 = Base.mul_int(x, x)::Int64
│ %2 = Base.mul_int(2, x)::Int64
│ %3 = Base.sub_int(%1, %2)::Int64
│ %4 = Base.mul_int(4, x)::Int64
│ %5 = invoke Base.factorial_lookup(%4::Int64, Base._fact_table64::Array{Int64,1}, 20::Int64)::Int64
│ %6 = Base.add_int(%3, %5)::Int64
└── return %6
) => Int64
This is me querying Julia for it's typed intermediate representation of the function `foo` I defined if the input is an integer. As you may be able to see, this is a statically typed program. So while Julia is a dynamic language, the interior of function bodies can be static if type inference succeeds. However, if type inference fails, Julia is also perfectly happy to just let chunks be dynamic.If you're having trouble understanding that code_typed output and are familiar with C, maybe the output LLVM instructions are helpful:
julia> @code_llvm foo(4)
; @ REPL[8]:1 within `foo'
define i64 @julia_foo_17575(i64) {
top:
; ┌ @ int.jl:52 within `-'
%1 = add i64 %0, -2
%2 = mul i64 %1, %0
; └
; ┌ @ int.jl:54 within `*'
%3 = shl i64 %0, 2
; └
; ┌ @ combinatorics.jl:27 within `factorial'
%4 = call i64 @julia_factorial_lookup_17503(i64 %3, %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140302197922128 to %jl_value_t*) to %jl_value_t addrspace(10)*), i64 20)
; └
; ┌ @ int.jl:53 within `+'
%5 = add i64 %4, %2
; └
ret i64 %5
}
Also, I encourage you to note that nowhere did I manually put a type annotation in my definition of foo. foo is a generic function and will compile new methods whenever it encounters a new type.