This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-02
Channels
- # announcements (3)
- # aws (8)
- # babashka (87)
- # babashka-sci-dev (3)
- # beginners (34)
- # calva (35)
- # clerk (2)
- # clj-commons (47)
- # cljdoc (10)
- # cljs-dev (21)
- # clojure (19)
- # clojure-android (1)
- # clojure-austin (2)
- # clojure-europe (30)
- # clojure-nl (1)
- # clojure-norway (67)
- # clojure-uk (9)
- # clojuredesign-podcast (7)
- # clojurescript (24)
- # code-reviews (20)
- # cursive (6)
- # datomic (12)
- # emacs (14)
- # events (1)
- # fulcro (7)
- # gratitude (1)
- # hoplon (8)
- # hyperfiddle (23)
- # juxt (22)
- # meander (11)
- # nyc (3)
- # overtone (2)
- # podcasts-discuss (1)
- # reagent (3)
- # releases (1)
- # sci (27)
- # shadow-cljs (73)
- # squint (4)
- # thejaloniki (3)
- # xtdb (7)
Hello, I would appreciate any suggestions on how I can improve my code. This code connects to multiple IRC servers, it can optionally connect using SSL and joins multiple channels. https://tildegit.org/fn/irc-bot/src/branch/main/src/irc_bot/core.clj
(doall (map connect servers))
making a lazy sequence just to immediately realize it is fine, but I would prefer (into (map connect) servers)
or (mapv connect servers)
.It's a little unintuitive that connected?
and disconnected?
aren't negations of each other.
I don't see any coordination for writing to a connection. This could cause interleaved writes in a multi-threaded context (which may or may not be a problem for your use case). One option might be to use a java.util.concurrent.ConcurrentLinkedQueue or similar.
Generally speaking, there are few operations that could be run from any thread. I might consider something like having a queue for each connection that make sure operations like disconnecting, joining, logins, etc aren't interleaved.
Personally, I reach for core.async for this kind of thing, but it's not everyone's cup of tea.
join-all-channels
returns a lazy sequence. I would prefer doseq
over for
in this context.
connect
initializes the connection with the :channels
key from server
, but doesn't otherwise join a channel or deal with channels. I would probably have connect
ignore :channels
from server
and include that info in conn
elsewhere (like join
)
Hey Adrian, I appreciate you responses, I am completely new to programming, I ask that you forgive me but what could go wrong in this case of uncordinated writes to the Socket’s output stream. I haven’t fully wrapped my head around a lot of the Java classes that I am using in this code.
The way connect currently works feels awkward and I am not sure if I am modelling things correctly. Good call on connect?
& disconnect
these are experimental and I have noticed odd behaviour with connected?
returning through even though the socket is closed.
This is my first project in Clojure and my aim is to learn how to model problems, as a professional engineer would. So any feedback towards that would be greatly appreciated.
> what could go wrong in this case of uncordinated writes to the Socket’s output stream.
for (.println (str msg "\r"))
, it basically means that it would be possible for multiple different messages to be written with characters interleaved: part of one message, followed by part of another, followed by part of another, etc. In some cases, it might be unlikely for short messages to be interleaved, but I find that it's usually best not to rely on implementation details.
yea, that should work.
Hi folks, Beginner here 😅. I made a url shortener to learn about web development in clojure. I had some trouble gluing the libraries at first, but now it seems to be working fine now(?). Here's the repo: https://github.com/rmrt1n/urlfrog I would love some feedback on the code and the project structure! Thanks!
It seems like creating a duplicate slug should return an error if it randomly chooses a slug that already exists, https://github.com/rmrt1n/urlfrog/blob/82c86db1ee5b6043ddaa5f36fd29a7e02a36a32a/src/urlfrog/routes/shorten.clj#L27
It doesn't seem like there's a uniqueness constraint on slug ids for your xt db.
The logic for creating a slug is coupled to the request handler. I recommend having a standalone function for dealing with slugs.
I see, thanks!