Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why "use clojure.string instead of interop"? #209

Open
rkc-rkc opened this issue May 7, 2020 · 3 comments
Open

Why "use clojure.string instead of interop"? #209

rkc-rkc opened this issue May 7, 2020 · 3 comments

Comments

@rkc-rkc
Copy link

rkc-rkc commented May 7, 2020

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.

@bbatsov
Copy link
Owner

bbatsov commented May 7, 2020

Two reasons:

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

@rkc-rkc
Copy link
Author

rkc-rkc commented May 7, 2020

* 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"

@bbatsov
Copy link
Owner

bbatsov commented May 8, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants