I’m quite new to Julia and so far I can say that I fairly like the language. Especially, the generic programming ability in combination with multiple-dispatch is a great idea which I explicitly love.
That said, I find it a pity that Julia is still located in a niche and has not yet managed to evolve into one of the mainstream languages. Referring to the talk of Jeremy Howard (https://youtu.be/s6pjxCuNGjc) at JuliaCon, I support his opinion that one of the main drawbacks of the language is the difficulty of creating static executables which are small in size and comparable with C or Fortran binaries. I understand, that the dynamic typing system of Julia demands to ship the compiler code along with the actual binary (to allow JIT compilation) which is in my opinion the main difference to a statically typed language (as C or Fortran) (sure, you need to ship some extra code for heap memory management, but I guess this could probably be optimized to some KB in native code size; please correct me here if I’m wrong).
However, in a lot of cases, I think JIT is not necessary for the actual final executable as the ‘main’ function often infers stable types to the code which, maybe, can be propagate throughout the whole program. Obviously, to make this work, every subfunction called with stable types (and fixed parameters) must guarantee that the types of the returned objects are inferable by those input types and, thus, stable and known at compile time. (Maybe one could allow a few variants of return types which are opened up, e.g., through branches in the code, but this is already something advanced and may be ignored in a first iteration). I think @code_warntype already manages to check the inferability quite well and, hence, in my view the next logical step would be to add something like an @inferable macro to functions which checks that all types can be inferred at compile time (in all possible cases). If not, the code should throw an error and refuse to compile. As alternative or as a complement a @typestable macro could check on a case-by-case basis (of actually given, fixed input types) if the return types are inferable (or type-stable).
Having such macros would have in my view two advantages:
- Declaring julia_main as @inferable/@typestable would allow the therefrom generated ‘app’ to be completely compiled ahead of time, avoiding the need to include compiler code and, thus, making the Julia executables comparable to C/Fortran binaries. Theoretically, the PackageCompiler just needs to look if the macro is defined and could then optimize the code generation accordingly. Maybe one could even add a static linking option in the future to really just include the needed code (all external Julia libraries should theoretically also be available as static libraries?).
- Having an inferable typing should also avoid a lot of performance issues if ‘real’ dynamic typing (e.g. random numbers generating random parameters for random types) is not wanted in the first place and just introduced erroneously.
I don’t know how much of Julia’s standard library and also external libraries are already @inferable by nature. But I assume a lot of them since ‘real’ dynamic typing (as in the example above) does not follow the spirit of multiple-dispatch in my view (it’s probably called multiple-dispatch and not infinitely-dispatch for a reason ).
I’m sure no expert of the language and I also don’t know if somebody else already proposed something similar (at least I did not find anything comparable on a quick search). There are maybe other ways to implement this (maybe through keywords or similar) or there is maybe something that renders my suggestion impossible to implement or useless for some other reason. But, if not, I’m glad if I could maybe inspire you to possible future improvements. I would gladly throw Python and Matlab over board and teach my students Julia from the first hour, but this is just possible if the language becomes more broadly accepted - and providing people with highly competitive (to C/Fortran) one-click solutions is probably one way to make this happen.