I’m totally new to Julia, but have some Rust, Zig and Python background.
I am using the Julia Language Server with VSCode. Even for type-stable functions, vscode does not show the return type of functions. And variables which are the results of functional calls, those types are not inferred either, even for type stable functions. (even for simple functions like from Example.jl)
hello(who::String) = "Hello, $who"
I have read in the manual this passage:
Return type declarations are rarely used in Julia: in general, you should instead write “type-stable” functions in which Julia’s compiler can automatically infer the return type. Functions · The Julia Language
So if writing type-stable functions are the best practice, shouldn’t the Language Server provide some information about variable types, and function return types? It’s quite surprising, having used the Language Server implementations for other languages, including Python.
That would be nice, but limited to functions with only one possible input (or output) type (like that of the example). And those are not very common. In general type stability and return types are properties of the funcion and of the input types together.
Here are the code help popups which the Python language server displays in VSCode:
# hover on f()
(function) f: (x) -> Any
# hover on var1
(variable) var1: int
# hover on var2:
(variable) var2: float
# hover on var3:
(variable) var3: str
A slightly different example with Python again, but using type hinting
def foo(b: bool) -> Optional[str]:
if not b:
return None
return 'ok'
# hover over foo:
# (function) foo: (b: bool) -> str | None
var4 = foo(True)
# hover over var4
# (variable) var4: str | None
No doubt there are lots of differences between Python type “hinting” system and Julia’s real type system. I am just trying to wrap my head around how this works