Sorry I missed this message! It’s been too long! Thanks for the question.
:require statements in the
ns declaration are doing two things. One, they’re saying “load this if it’s not already loaded”. So those are probably already loaded, especially on the reload. Two, they’re defining aliases, which is what the
:as directive is saying. The alias lets you refer to the namespace with a shorter name.
In the above code with that
core/db is equivalent to
webdev.core/db. It’s referring to the
db Var in the
Those aliases are only valid in the current namespace. Technically, you can refer to any public Var in any namespace–as long as it’s loaded–even without a
:require. For instance, I often call
clojure.string/join without requiring the namespace, because it’s usually already required. This isn’t good practice You never know whether something is required or not, and it really just depends on the order things get loaded. It’s better to
:require the namespaces your namespace uses.
That’s why you duplicate the
:requires. For the aliases (valid only for current namespace) and for modularity (namespace A shouldn’t have to know what namespace B requires).
The rules of thumb are simple: always require anything code in this namespace needs and nothing more. You’ll notice that the code above refers to code in each of the 4 required namespaces.