1

What's the most idiomatic way to use the :require and :use in the ns macro?

(ns app.core
  (:require [clojure.tools.logging :as log]
            [clojure.java.io :as io]
            [clojure.edn])
  (:use [compojure.core]
        [postal.core]
        [ring.adapter.jetty]
        [ring.middleware.multipart-params]))

or

(ns app.core
  (:require [clojure.tools.logging :as log])
  (:require [clojure.java.io :as io])
  (:require clojure.edn)
  (:use compojure.core)
  (:use postal.core)
  (:use ring.adapter.jetty)
  (:use ring.middleware.multipart-params))

or somehow else?

Is there any common guidelines or best practices?

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242

1 Answers1

2

Your first example is more idiomatic. However, the use of use or :use is discouraged, so the most idiomatic way would be this:

(ns app.core
  (:require [clojure.edn]
            [clojure.java.io :as io]
            [clojure.tools.logging :as log]
            [compojure.core :refer :all]
            [postal.core :refer :all]
            [ring.adapter.jetty :refer :all]
            [ring.middleware.multipart-params :refer :all]))

You may find it beneficial to try to follow the Clojure community style guide.

Sam Estep
  • 12,974
  • 2
  • 37
  • 75
  • What's wrong with the `:use`? It seems that `:require` combined with `:refer :all` is the same thing actually – FrozenHeart Sep 09 '16 at 19:30
  • @FrozenHeart I would encourage you to read the [many](http://stackoverflow.com/q/871997/5044950) [posts](https://8thlight.com/blog/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html) [on](http://dev.clojure.org/jira/browse/CLJ-879) [this](http://stackoverflow.com/q/10358149/5044950) [topic](http://grokbase.com/t/gg/clojure/137qrc7xmr/can-we-please-deprecate-the-use-directive). – Sam Estep Sep 09 '16 at 19:35