January 2020
Intermediate to advanced
532 pages
13h 31m
English
While getter and setter functions are convenient, it is easy to forget about these functions and so the program ends up accessing the fields directly. That would be too bad, as we have just spent all that effort creating getter and setter functions and they end up getting bypassed.
A possible solution is to discourage direct field access by renaming the fields to something that looks obviously private. A common convention is to prepend the field names with underscores.
For our example, we can redefine the struct as follows:
mutable struct Simulation{N} _heatmap::Array{Float64, N} _stats::NamedTuple{(:mean, :std)}end
These oddly named fields will then only be used within the implementation of the Simulation ...
Read now
Unlock full access