Should example code use :use or :require

10 views
Skip to first unread message

Paul Williams

unread,
Mar 29, 2015, 12:39:24 PM3/29/15
to mi...@googlegroups.com
I've just noticed that the excellent examples for Midje use the :use rather than the generally preferable :require. I've just refactored my tests using midje to :require and all is well.

I wondered whether there were other reasons for using :use in these docs, and if not would you accept a PR / alternative assistence to change these?

Paul

Brian Marick

unread,
Apr 9, 2015, 4:48:24 PM4/9/15
to mi...@googlegroups.com
[I have returned to the ranks of the unemployed and so have more time
for Midje.]

Paul Williams wrote:
> I wondered whether there were other reasons for using :use in these
> docs, and if not would you accept a PR / alternative assistence to
> change these?

I prefer `:use` to `:refer :all` in almost all cases because:

1. It is visually more distinct and signals something important: "the
namespace I'm hereby mentioning in `ns` is so central to the purpose of
this whole "module" I'm writing that I'm using its symbols without the
usual qualifiers (from `require :as`)." Exceptional uses should look
exceptional, rather than being one of N requires.

2. I don't see why it's so wonderful to have one mechanism `require` do
so many things.

In practice, I use `:require :as` for almost everything, except
`midje.sweet` and `project.clojure.core`, which contains all those
things I wish were part of `clojure.core`.

That said, I never convince anyone of this view, so I'd be happy for you
to go ahead and change it if you like. And there's virtue in following
custom, even if that custom is wrong, Wrong, WRONG!

(Note that a lot of the Midje code was written before I realized the
virtues of `:require :as`. It's never been changed.)
Reply all
Reply to author
Forward
0 new messages