-
Notifications
You must be signed in to change notification settings - Fork 279
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
Comments
Two reasons:
|
Style guide by definition is subjective and this is fine with me
That had not crossed the mind. Thanks. |
Yeah, I totally agree this should be formulated in a more generic manner. |
It should be noted that in the case of upper-case, if you are writing code only for the JVM or JavaScript, the Clojure and ClojureScript implementations of clojure.string/upper-case are ostensibly the same, calling the native .toUpperCase method (Clojure CLR uses the differently named .toUpper native method). So for most people .toUpper (and friends) are effectively portable, which perhaps makes it a less-than-ideal example for the interop vs built-in argument. I would also say that, to me at least, ".toUpperCase" is at least as readable as "upper-case". Elegant and seamless interoperability is rightly touted as one of its outstanding features, so we shouldn't be afraid to use it, especially for trivial cases where you understand your target environment. That said, a compelling counterargument what I have just said is that there's no actual benefit to using .toUpperCase over upper-case in terms of your program's runtime size or performance. Your code gets compiled into pretty much the same thing irrespective of what approach you use, so what we're really talking about here is how much we object to the extra keystrokes needed to use the Clojure implementation, either through requiring clojure.string or using the qualified clojure.string/upper-case form. Personally, I've heard all the arguments [😁], and I think I come down on the side of using the provided Clojure functions. |
In Clojure 1.12, this is (mostly) the difference between: (String/.toUpperCase foo)
;; and
(str/upper-case foo) ; assuming `(:require [clojure.string :as str])` which a lot of nses have I assume ClojureScript 1.12 would be the same (when it gets there), but I suspect not all |
From the doc ==>
But looking at clojure.string/upper-case
it is but a call to interop. It will be nice to know why one is preferred over the other.
The text was updated successfully, but these errors were encountered: