Fork me on GitHub
#calva
<
2022-08-11
>
rfisher11:08:12

Not sure if this is a Calva thing or a clj-kondo thing, (and I'm pretty certain it's a "me" thing) but I don't understand why, when I have code like this

(ns core
  (:require [clojure.string :as str :refer [split-lines split trim]]))

...

(defn load-input-lines [file]
  (str/split-lines (load-input-raw file)))
I get a problem telling me
#'clojure.string/split-lines is referred but never used

borkdude11:08:55

Do you have more output that still needs to be flushed? ;)

rfisher11:08:51

Sorry, I missed a control. Trying to learn all the Calva shortcuts is getting to me 🙂

borkdude11:08:21

Ah. You're getting this message because the :refer for split-lines wasn't necessary here since you used the alias

rfisher11:08:56

I think this is actually the crux of my question. kondo is clearly trying to help me here, but i can't quite grasp what it's telling me.

borkdude11:08:15

if you write (split-lines ...) the message would go away - does that make sense to you?

borkdude11:08:46

I agree that the message is confusing in this case

rfisher11:08:05

Ah! Yes! I get it now!

rfisher11:08:07

I find the stuff in (ns) maybe the hardest part of clojure to get my head round.

borkdude11:08:01

From what language are you coming?

rfisher11:08:38

Mostly Ruby

pez11:08:29

I tend to use either an namespace alias or refers, preferring aliasing the ns. And in case of clojure.string I always alias it and always use string as the alias. I know str is ubiquitous, but there is a function named str that does not live in this ns, and I like to be able to distinguish them by the name only.

rfisher11:08:15

there seem so many ways to bring things into scope. Things work, but maybe aren't the right way. This is why I really like having a tool like kondo, and why I like to understand what it's telling me.

rfisher11:08:37

Is there any penalty in pulling in all of, say clojure.string rather than specifying what you need?

pez11:08:01

I don't think threre is.

borkdude11:08:05

I mostly use (str/...) as the alias

rfisher11:08:26

In that case then, I like require :as and specify the prefix in the code. That seems simplest and clearest to me.

👍 2
rfisher11:08:10

Thanks everyone.

pez13:08:42

A related note is that sometimes you can get away without the require and use the fully qualified name directly. As long as the namespace is loaded this will work. However, it is bad practice as your program can stop working by the removal of some seemingly unrelated file. clj-kondo helps avoiding this mistake.