Dynamic typing checks types while a program runs. Values carry type information, allowing runtime checks to determine whether an operation is valid. By contrast, static typing checks code before execution. section 1.1.1
Dynamic typing is useful in interactive workflows: load a dataset, inspect it, change an analysis, and observe the result without necessarily reloading the data. The type system alone does not guarantee this workflow; it also depends on the programming environment. section 1.3.1
Figure 1.1 In dynamically typed languages you can ping-pong between coding and observing. Large data sets do not need to be reloaded into memory.
Follow the loop between changing code and observing results while a large dataset remains in memory. section 1.3.1
Experimenting with a neural network
Python can arrange components implemented in C or C++ for TensorFlow or PyTorch. A developer can rearrange those components without reloading the whole program. Another approach is to develop a model in a dynamic language, then rewrite it in a faster language—a costly extra step. section 1.3.2
Julia aims to combine dynamic typing with high performance, reducing the need for that two-language workflow. It was designed for just-in-time compilation and uses multiple dispatch for function calls. A language and its execution method are distinct, however: Julia can also run through an interpreter. section 1.1.1 section 1.4
Runtime flexibility can involve overhead. Boxed values can carry bookkeeping information such as type and garbage-collection details. Julia’s composite types restrict fields: their names are fixed by the type, and stored values must match the field types. These restrictions help the JIT compiler generate optimized code. section 18.4
Listing 18.11 Pseudocode of how multiply would work in a normal dynamic language
function multiply(u::Vec2D, k::Number)
ux = getfield(u, :Δx)
if !isa(ux, Float64)
error("x must be a float")
end
uy = getfield(u, :Δy)
if !isa(uy, Float64)
error("y must be a float")
end
c = convert(Float64, k)
Vec2D(floatmul(c, ux), floatmul(c, uy))
end
This illustrative pseudocode shows runtime field lookups and type checks when scaling a vector; it is a rough model, not an exact implementation. section 18.4





