I've been needing a reason to do more regular posts and this Collections features seems like a good way to organize content streams. This collection is called "Julia Programming Tips" and I'll try to post fairly frequently with tips and tricks (since I spend at least some time every day coding, I should
be able to find something to post about...).
*Note: If you don't care to see updates about programming/Julia, you can navigate to my profile page (by clicking on my picture), then click on "Collections" and then click "Following" on the "Julia Programming Tips" collection to not see these posts.
As a package maintainer, how do I maintain a single code source instead of branching different versions (say for version 0.3 vs. 0.4)?
This is a great question with a relatively new answer. Originally there was the `VERSION` variable defined in Base that allowed one to put something like:
if VERSION > v"0.4.0"
# version 0.4 code
# version 0.3 code
While this works, it's a little clunky because often times the new feature/syntax you want to use was introduced at a specific commit, so just specifying `v"0.4.0"` means anyone on 0.4, but that doesn't yet have the new commit will see errors. It then becomes a hassle to track down the exact commit relative to 0.4 to version off of (e.g. `v"0.4.0-dev+4928"`). What's worse is that new syntax may not even be parseable in the new commit.
Enter Compat.jl (https://github.com/JuliaLang/Compat.jl
). Compat.jl is a package that maintains compatibility changes between versions in Julia. It's a central repository for all
packages to use to simplify the versioning process and provide an easy way to use new features/syntax in packages, while easily maintaining backwards compatibility. Like the new Dict syntax in 0.4? Try this:
new_fancy_dict_of_lies =@compat Dict("money" => "happiness")
Boom! Code automatically compatible between versions of Julia. Super simple stuff.
Anyway, that's it for today's Julia tip, feel free to ask any questions, suggest future tip topics, or, shudder, correct my code :
( Have a swell day!