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?

maxcountryman
  • 1,562
  • 1
  • 24
  • 51
  • 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 08 '13 at 02:00
  • 10
    Pro tip: `lein new foo.bar` will create `foo/bar` rather than `bar/core`. – deprecated Apr 08 '13 at 04:32
  • @noahz do you have a link? I'm curious to read Stuart's opinions about this. – maxcountryman Apr 08 '13 at 16:04
  • Sorry, it was on twitter, and it might have actually been someone else, not Stuart. – noahlz Apr 08 '13 at 17:34

1 Answers1

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.

Paul Legato
  • 1,202
  • 13
  • 11