(Word of warning, I’m not well-versed in programming in general and have only used Python for simple tasks, so it would be helpful for me if even simple concepts are explained with some detail.)
I’m interested in trying Julia for its dynamic typing and high performance. I’ve read multiple articles explaining that this is done via multiple dispatch and type stability. In simple terms, we can write a function with unspecified types like in Python, but Julia will compile a method for each combination of argument types upon the first call. If Julia can expect a specific return type for a method, it makes something like a C function where all input and output types are specified. Therefore, Julia can be easy to write like Python and can have the efficiency of C.
However, these articles don’t go beyond that, and I do have questions about how this works:
-
Say I write a function that has an if statement to check an argument’s type (bear with me, I know it’s easier to just write separate methods) and do different things depending on it. Am I correct in thinking that Julia is smart enough to make a method for each condition?
-
If a function call within the main function is not type-stable, am I correct in thinking that Julia must incorporate type checking after that function call and select from different compiled subroutines? If so, how does Julia implement this? Does it update the method as unexpected types show up?
-
I read that type-unstable functions have a performance cost due to the increased need to type-check. I can see that adding up to a large problem if it is called in other functions and forces THOSE functions to type-check, or if it is heavily repeated as in a for-loop, but is it that big of a deal if it is only intended to be called manually?