Workflow Tips¶
Here are some tips for working with Julia efficiently.
REPL-based workflow¶
As already elaborated in Interacting With Julia, Julia’s REPL provides rich functionality that facilitates an efficient interactive workflow. Here are some tips that might further enhance your experience at the command line.
A basic editor/REPL workflow¶
The most basic Julia workflows involve using a text editor in
conjunction with the julia
command line. A common pattern includes
the following elements:
Put code under development in a temporary module. Create a file, say
Tmp.jl
, and include within itmoduleTmp<yourdefinitionshere>end
Put your test code in another file. Create another file, say
tst.jl
, which begins withimportTmp
and includes tests for the contents of
Tmp
. The value of usingimport
versususing
is that you can callreload
("Tmp")
instead of having to restart the REPL when your definitions change. Of course, the cost is the need to prependTmp.
to uses of names defined in your module. (You can lower that cost by keeping your module name short.)Alternatively, you can wrap the contents of your test file in a module, as
moduleTstusingTmp<scratchwork>end
The advantage is that you can now do
using
Tmp
in your test code and can therefore avoid prependingTmp.
everywhere. The disadvantage is that code can no longer be selectively copied to the REPL without some tweaking.Lather. Rinse. Repeat. Explore ideas at the
julia
command prompt. Save good ideas intst.jl
. Occasionally restart the REPL, issuingreload("Tmp")include("tst.jl")
Simplify initialization¶
To simplify restarting the REPL, put project-specific initialization
code in a file, say _init.jl
, which you can run on startup by
issuing the command:
julia-L_init.jl
If you further add the following to your .juliarc.jl
file
isinteractive()&&isfile("_init.jl")&&require("_init.jl")
then calling julia
from that directory will run the initialization
code without the additional command line argument.