Yes, the converse applies: if something is genuinely variable, make it a variable. At which point itās certainly not bad behavior for a user to modify it, thatās expected behavior, and a dot-syntax on modules is coherent with the rest of the language.
What isnāt good is mutable global state which isnāt resilient to mutation from outside the module. Iām trying to avoid being doctrinaire here, but that combination very often means that changing that global state will modify behavior from āupstreamā of the change, and thatās a bad problem to have. The user setting that global to the wrong value is merely a special case of the problems which might arise.
public
and private
donāt have to carry the same semantics they carry in languages which get them from C++. Juliaās upcoming public
is documentation, as I understand it, a way of marking something explicitly as part of the API without exporting it. It wouldnāt be needed if Julia didnāt have the using
keyword, but it does, and in my opinion the convenience of using
makes up for the problems it can cause.
private
, if itās ever added, can serve to prevent access to a variable outside of the defining module. The compiler could use that directive to eliminate the symbol entirely, so thereās no variable left to access, just compiled references to the memory itās using. Whether this is philosophically compatible with Julia isnāt something I have an opinion on, but itās definitely possible to add a feature like that.
I wish ImmutableDict
were called something else, actually, like AList
, because thatās what they are: a linked list of key/value pairs. Plenty of times that such a thing is useful, but it isnāt useful for my case, because adding a second definition of a key shadows the first. What Iād like is a Dict where redefining a key has no effect, Base doesnāt have one of those, and itās not quite worth writing my own wrapper struct over Dict to provide that behavior. At the end of the day, itās the userās code once they load it, if they want to break it, Iām not strongly motivated to prevent them from doing so.
I would make it private
as well as const
if it were possible to do that, fwiw. itās intended to be an append-only cache, which is only added to using a particular function, and if I could enforce that as an invariant, I would, itās good practice.