Hi, I am implementing the htmx official examples in Clojure as a learning exercise. I'm done with most of the examples. There's a few left and I'll finish soon. Any input into how I can write more idiomatic code and anything I'm doing wrong is welcome. I can refactor as needed with input. Thanks. Repo here: https://github.com/nakiya/htmx-examples-clojure
(defmethod ig/init-key ::dev-mode? [_ v]
(println (str "System starting in " (if v "dev" "prod") " mode."))
v)
(defmethod ig/init-key :server/opts [_ v] v)
(defmethod ig/init-key ::server [_ {:keys [server-opts dev-mode?]}]
(server/start-server dev-mode? server-opts))I don't see how these line up exactly
(defonce ^:private sessions (atom {}))
(defn- create-session-and-get-id [session-id]
(swap! sessions assoc session-id (atom nil))
session-id)
(defn- get-session [session-id]
(get @sessions session-id))this mutable state should live in the system and come in as an argument
@emccue Thank you for the suggestions. Will incorporate!
🤷 sorry I didnt have time to dig that deep into the rest of your code
pet peeve though - even though the (comment block at the bottom is common as a place to experiment
I think that any code left in that sort of block when you commit your code should also be a "script"
like
instead of
(comment
(some-func nil)
;;(some-func [])
(some-func "hello"
)
)(comment
;; Expect A
(some-func nil)
;; To test no results
(some-func [])
;; Basic case
(some-func "hello"))I know thats vague, but
(comment
(re-matches #"sessionId=(.*)" "sessionId=what")
(require '[hiccup.page :as page])
(page/html5 [:div])
,,)I don't mind your #_f to make the formatter leave the ) on its own line. Its not something I personally care about but it does feel like its a valid choice
personal style can exist
Basically comment blocks should have stuff that make sense for readers and shouldn't be like simply nonsense from trying things out. Makes sense. Again, thanks.
a corollary is to make sure anything you did as an experiment that was useful is captured either in the "final" comment block or as a unit test