9

I'm relatively new to Clojure but I've noticed many projects implement a "core" namespace; e.g. foobar.core seems to be a very common pattern. What's the history behind this and why is it the de facto standard?

4
  • Probably just following the clojure.core convention. However, Stuart Sierra and others are outspoke about every library (and default Leiningen projects) overusing whatever.core.
    – noahlz
    Apr 8, 2013 at 2:00
  • 10
    Pro tip: lein new foo.bar will create foo/bar rather than bar/core.
    – deprecated
    Apr 8, 2013 at 4:32
  • @noahz do you have a link? I'm curious to read Stuart's opinions about this. Apr 8, 2013 at 16:04
  • Sorry, it was on twitter, and it might have actually been someone else, not Stuart.
    – noahlz
    Apr 8, 2013 at 17:34

1 Answer 1

2

It's just a generic name that represents the "core" functionality of something. The core functions of Clojure itself define a general purpose programming language, with very generic functions you might need in many different problem domains. Functions which are only applicable to a specific problem domain go into domain-specific namespaces, such as clojure.string or clojure.set.

Tools like Leiningen can't know a priori what sort of a program you're trying to write, so they set you up with a foo/core namespace by default, modelled after clojure.core -- clojure.core is the core functionality of Clojure, so foo.core is the core functionality of foo.

If you can give your core namespace a less generic name, or just use foo/core to kick off bootstrapping (such as by holding your -main function), that's encouraged, so that the bulk of your code will reside in more semantically meaningful namespaces instead. This helps you find the specific code you want to work on later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.