Suggestion --- Julia Version Header in .jl files

May I suggest that we ask Julia .jl code files in the future to start with a very short (and possibly optional) header line, such as

julia 1.0

If the language in the future changes in a breaking way, then there is a fallback to keep old code going, without holding back good changes for subsequent versions. This is related to requiring package versions ids.

Julia packages already have a REQUIRE file in which a Julia version bound can be specified.

2 Likes

this is good for packages. it is not the case for user files. to allow breaking language changes, I think it needs to be in the .jl files themselves, both users and packages.

Seems like a good idea to me, I agree it could be useful. One thing you could do is write a macro or function that checks the julia version at the beginning, for example

julia> check(version) = VERSION ≠ version && throw(error("wrong Julia version"))
check (generic function with 1 method)

julia> check(v"1.2.0")
ERROR: wrong Julia version
Stacktrace:
 [1] check(::VersionNumber) at ./REPL[3]:1
 [2] top-level scope at none:0

could throw an error if your Julia version is not correct. That’s one way I could see of doing it, if it does not end up being included in the Base language, you could open an issue on JuliaLang github page.

I like the check(version) idea. I’ve been using direnv to help with Julia versioning and environment handling per directory. It works great once set up (on Linux; Windows is tough).

everyone can do this for their own code.

however, the big advantage of prescribing the use of such a feature is that it will give the julia language developers more freedom and flexibility to deprecate aspects in the distant future. and the time to implement this feature is right now, when it is not hurting anyone.

it could also be required as a comment, like #!julia 1.0

a secondary advantage is easy recognition of julia source code (by file).

/iaw

This sounds a good idea. However, I have never see this kind of stuff automatically generated in any programming language I have used. Maybe it is better to be left to user decision. Actually there are lot of things to be checked. Do we also need to check if a specific package has been installed? Do we also need to check if a specific package has the specific version the current file needs? etc.

I am not sure if this kind of version control tasks cannot be solved by just one header code…

Consider shebang (https://en.wikipedia.org/wiki/Shebang_(Unix)).

In unix world it is standard way how to chose interpreter for script. For example you could have Julia 0.6.x and Julia 1.x installed and use:

#!/usr/bin/env julia0
println("Hello, World! $VERSION")

to choose Julia 0.6.x - if you will have julia0 linked (in $PATH) to appropriate Julia 0.6.x binary.

I guess

@assert v"1.0.0" ≤ VERSION 

and similar could work, without introducing any extra constructs.

4 Likes