Skip to content


Good advice on miscellaneous topics:

Artifacts (1.6)

A useful guide: Artifacts for Dummies

Dates (1.6)

Working with time durations seems to require converting the durations to millisecond integers first:

d1 = DateTime(2021,9,10,9); d2 = d1 + Minute(3) + Second(5);
dSeconds = Dates.value(d2-d1) / 1000;

Going back to time units requires rounding because Minute(dSeconds) throws an InexactError.

dMinutes = Minute(round(dSeconds / 60));

There is no formatted display of durations, only of dates:

Dates.format(d1, "HH:MM");

Enum (1.6)

@enum Fruit apple=1 orange=2 kiwi=3

The type is Fruit (concrete). So dispatch on the instances does not work. The alternative: Defint an abstract type with concrete subtypes Apple <: AbstractFruit.

Benefits of enum:

  • Array{Fruit} is more efficient than Array{AbstractFruit}.

Benefits of types:

  • Static dispatch.
  • Can be extended.


For new DataTypes, it is necessary to defined hash, ==, and isequal. hash is needed for containers such as Dicts (it is used for haskey). The way this is done can be based on AutoHashEquals.jl:

mutable struct Foo
Base.hash(a::Foo, h::UInt) = hash(a.b, hash(a.a, hash(:Foo, h)))

Interpolation (1.6)


An example from QuantEcon.

One limitation: multi-dimensional interpolation only works with unform grids. The inputs must be ranges.

The default for extrapolation is to throw an error.


xV = 1:10; yV = 5:10;
zM = xV .+ yV' .+ xV .* yV';
itp = CubicInterpolation((xV, yV), zM);
itp(1.5, 5.9)

The same (?) interpolation can be constructed the long way round:

itp2 = interpolate(zM, BSpline(Cubic(Line(OnGrid()))));
sitp = scale(itp2, xV, yV);

One difference is that bounds works on sitp but not on itp.

Latex Output (1.6)

Latexify.jl renders various expressions as Latex equations. This is useful for automatically making expressions for functional forms. Also generates Latex tables from DataFrames and Arrays.

Logging (1.6)

@debug can be used to generate self-test code that is only run while developing the code.


# test1.jl
a = 1;
b = [1,2,3];
@debug begin
   bSum = sum(b);
   Debug message
@debug "Debug with args:"  a, b

To run this with the @debug statements enabled, issue (in the shell):

export JULIA_DEBUG=all
julia "test1.jl"

But this generates lots of debug messages that sit in Base. To avoid this, export JULIA_DEBUG=MyPkg.

Enabling logging levels temporarily:

lg = ConsoleLogger(stderr, Logging.Debug);
with_logger(lg) do


lg = ConsoleLogger(stderr, Logging.Debug);
old_logger = global_logger(lg);

Random numbers (1.5)

Generating reproducible random numbers across Julia versions can be done with StableRNGs.jl. This also seems to generate the same random numbers across operating systems (in my case MacOS and Linux).


An interesting implementation is WhereTraits.jl which permits, for example, dispatch on functions that return Bool.