This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-06-07
Channels
- # announcements (1)
- # beginners (123)
- # calva (17)
- # clj-kondo (16)
- # cljfx (1)
- # cljs-dev (4)
- # clojure-austin (1)
- # clojure-conj (1)
- # clojure-europe (28)
- # clojure-nl (3)
- # clojure-norway (25)
- # clojure-sweden (8)
- # clojure-uk (6)
- # conjure (4)
- # datahike (30)
- # datalevin (2)
- # datomic (2)
- # docker (4)
- # events (1)
- # fulcro (6)
- # graalvm (9)
- # gratitude (1)
- # honeysql (7)
- # hyperfiddle (29)
- # introduce-yourself (2)
- # jobs (2)
- # off-topic (18)
- # pedestal (5)
- # reitit (3)
- # releases (3)
- # remote-jobs (3)
- # scittle (18)
- # shadow-cljs (31)
- # tools-build (44)
- # tools-deps (10)
I was thinking about a new linter that might be interesting for others as well. It would give a warning on a function that is using bang functions and if its name is not ending with an exclamation mark. This would trigger a warning:
(defn something
(swap! atom inc))
This would not:
(defn something!
(swap! atom inc))
such linter might get very annoying in case you have a stack of multiple function, one calling another.
(defn baz []
42)
(defn bar []
(baz))
(defn foo []
(bar))
(foo)
after changing baz
to use swap!
or other "bang" function you probably will have either an explosion of warnings everywhere or only one upon fixing which a new one pops up.
(def x (atom nil))
(defn baz [] ;; warning here
(reset! x 42))
(defn bar []
(baz))
(defn foo []
(bar))
(foo)
;;; after fix
(def x (atom nil))
(defn baz! []
(reset! x 42))
(defn bar [] ;; warning here
(baz!))
(defn foo []
(bar))
(foo)
yes, true, but I was thinking about enabling this for a certain namespace, like DB models
and not enable for the whole app
yeah, I see how and where this might be useful. But even within a single namespace the problem with a sudden new warning after fixing another might happen.
yes, definitely there is an avalanche effect, but for a DB model namespace, I believe that would be even favorable
haha, kind of, yeah 😅
> such linter might get very annoying in case you have a stack of multiple function, one calling another. Sounds like a feature, not a bug when a function deep down in the call stack turns side-effecting 😄
How does that behave with a higher order function? I’m guessing static analysis would miss that, right? (defn f [f-bang] (f-bang 7)) (defn f! [n] (println n)) (f f!)
Yeah, but in that case the mutating function is the argument, not the caller.
(do (f f!) (f str))
You don’t want to rename the map
function to map!
just because it can receive a mutating fn