First let me say I know nothing about Julia.
I have read the following StackExchange post:
As the author says, Julia is dynamically typed. However, as Julia’s website explains, the semantics of Julia are more restrictive than those of Python or R, which enables compilation to highly performant code.
Let us generalize beyond the author’s definition of static typing as “every expression has a type” and consider static analysis more generally, I am interested in the broader question of how much feedback can we get from Julia’s static analysis tools before program execution. A friend of mine has told me in casual conversation:
If you’re writing Julia code where your types aren’t inferable, that’s understood to be an error, and all the built in profiling tools will yell at you. So it seems kinda similar [to OCaml], I’m just allowed to write bad Julia code if I want to. Which I often do, when I’m prototyping - and then I profile it, and it can’t infer the types, and I fix it, and it’s like 1000x faster because now the compiler can work better.
It is easy to write bad Julia code. Optimal Julia code looks very different from what you write in initial prototyping. But if you use the profiling and benchmarking utilities, you can write very fast code that works well and seems pretty safe.
As an outsider to Julia, this observation is really interesting to me. If I could write OCaml code initially in some kind of untyped language extension of OCaml (code which is wrong for edge cases, for example, but works in the primary cases of interest in my program) and then gradually modify it into type compliance, I can imagine that this would be very useful, and it illustrates why Julia is popular.
My question for the community is, if one is interested in writing safe, correct Julia code (potentially working in a more restricted fragment of the language, so giving up some of its dynamic flexibility), can we get good guarantees about the correctness of Julia programs through static analysis that are comparable to what is available in truly statically-typed languages? Is there a statically typable “core” sublanguage of Julia in which it’s possible to be as confident about our code as in OCaml?
I would imagine the answer is “no,” however, I would be interested in hearing practical and concrete examples in your code where
- static analysis tools for Julia did help you catch errors which would not be realistic to catch in Python or untyped Javascript
- there was a error in your code where static analysis tools didn’t help you but but the error would have been caught in a true statically-typed language such as OCaml or Haskell