Workflow Tips
REPL-based workflow
As already mentioned in the chapter REPL Julia, REPL Julia provides extensive functionality that contributes to the implementation of an effective interactive workflow. Here are some tips that will make it even more productive to work with the command line.
Basic editor workflow or REPL
The most basic Julia workflows provide for the usage of a text editor in combination with the 'julia` command line.
Create a file, say `Tmp.jl', and include the following snippet in it.
module Tmp
say_hello() = println("Hello!")
# Место для других ваших определений
end # модуль
using .Tmp
Then, in the same directory, run REPL Julia (using the julia
command). Execute the new file as follows:
julia> include("Tmp.jl") julia> Tmp.say_hello() Hello!
Analyze the ideas in the REPL. Save the good thoughts in the file Tmp.jl'. To reload a file after it has been modified, simply include it with `include
again.
The key point in the above actions is that your code is encapsulated in a module. Now you can edit the structure definitions (struct
) and delete methods without restarting Julia.
(Explanation: structures (struct') cannot be edited after definition, nor can methods be deleted. But you can overwrite the module definition, which is what we do when we reuse `include("Tmp.jl")
.)
In addition, encapsulating the code in a module protects it from the influence of the previous state in the REPL and, therefore, from hard-to-detect errors.
Browser-based workflow
There are several ways to interact with Julia in the browser:
-
using interactive Pluto scripts by https://github.com/fonsp/Pluto.jl [Pluto.jl];
-
using Jupyter interactive scripts via https://github.com/JuliaLang/IJulia.jl [IJulia.jl].
Revise-based Workflows
Regardless of whether you are in REPL or in IJulia, you can improve your development skills with https://github.com/timholy/Revise .jl[Revise]. As a rule, Revise can be configured so that it runs every time Julia is started. See the instructions in https://timholy .github.io/Revise.jl/stable/[documentation for Revise]. After configuration, Revise will monitor file changes in any loaded modules and any files loaded into the REPL using includet
(but not using the usual `include'). You can then edit the files and the changes will take effect without restarting the Julia session. The standard workflow is similar to the REPL-based workflow described above, with the following changes.
-
Put the code in the module at some place in the download path. There are several options for this task. It is recommended to choose two of them.
-
For long-term projects, use the package https://github.com/invenia/PkgTemplates.jl [PkgTemplates].
using PkgTemplates t = Template() t("MyPkg")
An empty package
"MyPkg"
will be created in the.julia/dev
directory. Note that PkgTemplates allows you to manage many different options using theTemplate
constructor.In step 2 below, edit the file
MyPkg/src/MyPkg.jl
to change the source code, and the fileMyPkg/test/runtests.jl
for the tests.-
In trial projects, you can avoid cleanup by doing work in a temporary directory (for example,
/tmp
).Navigate to the temporary directory, launch Julia, then follow these steps.
julia-repl pkg> generate MyPkg # type ] to enter pkg mode julia> push!(LOAD_PATH, pwd()) # hit backspace to exit pkg mode
If you restart your Julia session you’ll have to re-issue that command modifyingLOAD_PATH
. In step 2 below, edit the fileMyPkg/src/MyPkg.jl
to change the source code, and create any test file.
-
-
-
Create a package
Before loading the code, make sure that Revise is running, for example, using
using Revise
, or follow the documentation for configuring it to run automatically.Then go to the directory containing the test file (here it is assumed that it is
"runtests.jl"
) and do the following.julia> using MyPkg julia> include("runtests.jl")
You can iteratively modify the code in MyPkg in the editor and re-run the tests using `include("runtests.jl")'. As a rule, it is not necessary to restart the Julia session to see that the changes have taken effect (taking into account some https://timholy .github.io/Revise.jl/stable/limits/[limits]).