3 ms·
Never had a proper look at the documentation until now. This language is very interesting! One thing I found is that types in Julia are first-class values [0].
by AriaMinaei 8y ago
Never had a proper look at the documentation until now. This language is very interesting!
One thing I found is that types in Julia are first-class values [0]. You can put them in variables, pass them around, inspect them, even produce new ones in runtime. Opens up all kinds of metaprogramming opportunities. Very Lispy! (Well, Julia is Lispy). It's also interesting that types are optional, yet they're significant for the optimising compiler. Like, if you do type the arguments of a function, the optimising compiler will have less work to do.
It also looks like much of the compiler pipeline is exposed to the user [1]. You have access to the parser, can tweak the AST. Macros also there of course.
[0] https://docs.julialang.org/en/stable/manual/types/ https://docs.julialang.org/en/stable/manual/types/
[1] https://docs.julialang.org/en/stable/manual/metaprogramming/ https://docs.julialang.org/en/stable/manual/metaprogramming/
- StefanKarpinski 8y ago> Like, if you do type the arguments of a function, the optimising compiler will have less work to do. Giving types for function arguments doesn't actually have any effect on performance: the compiler specializes on concrete runtime argument types anyway, so completely untyped code is just as fast as fully type annotated code—since the types are known when the code is compiled. On the other hand, giving type information is essential for performance involving memory locations, i.e. field types and the element types of collections.
- AriaMinaei 8y agoThanks for the correction!
- ScottPJones 8y agoI've actually seen many cases where overuse of concrete types (on function parameters) in Julia can lead to poor performance. For example, if functions are written declaring an argument as `Vector{Int64}`, and then people using the function end up calling `collect` (and causing a lot of memory allocations), when they had a value that was an iterator and were forced to convert it into a vector just to call the function. Simply leaving off the `::Vector{Int64}` and getting rid of the `collect` on the caller speeds things up nicely.