bbatsov/clojure-style-guide

Why "use clojure.string instead of interop"?

rkc-rkc opened this issue · 5 comments

From the doc ==>

(clojure.string/upper-case "bruce")

;; bad
(.toUpperCase "bruce")

But looking at clojure.string/upper-case

user=> (source clojure.string/upper-case)
(defn ^String upper-case
  "Converts string to all upper-case."
  {:added "1.2"}
  [^CharSequence s]
  (.. s toString toUpperCase))

it is but a call to interop. It will be nice to know why one is preferred over the other.

Two reasons:

  • reads better (subjectively)
  • portable across Clojure implementations. All interop calls tie you to the underlying platform.
* reads better (subjectively)

Style guide by definition is subjective and this is fine with me

* portable across Clojure implementations. All interop calls tie you to the underlying platform.

That had not crossed the mind. Thanks.
May I then suggest the title "Use platform agnostic methods to improve portability"

Yeah, I totally agree this should be formulated in a more generic manner.