Clojure China

哪个更好?multi-arity or varargs style

clojure
#1

(let [[a b & c :as d] [1 2 3 4 5]]
(println a) ; 1
(println b) ; 2
(println c) ; (3 4 5)
d) ;[1 2 3 4 5]

Explicit multi-arity is strongly preferable to varargs style.

  1. You will get an error if you make a mistake and pass too many args rather than mysterious bad behavior.
  2. Later refactorings can proceed with confidence that there are no callers passing a bunch of extra ignored args.
  3. varargs results in a seq call plus destructuring - extra work that is slightly worse for performance.