This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-08
Channels
- # adventofcode (49)
- # announcements (2)
- # architecture (4)
- # babashka (48)
- # babashka-sci-dev (4)
- # beginners (7)
- # biff (1)
- # calva (14)
- # cider (6)
- # clj-kondo (1)
- # clj-yaml (1)
- # cljsrn (3)
- # clojure (14)
- # clojure-art (12)
- # clojure-europe (62)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-uk (5)
- # clojurescript (18)
- # clr (4)
- # community-development (9)
- # conjure (2)
- # core-async (3)
- # cursive (2)
- # datomic (2)
- # emacs (8)
- # events (3)
- # graalvm (1)
- # helix (6)
- # holy-lambda (3)
- # jobs (1)
- # off-topic (16)
- # polylith (30)
- # practicalli (11)
- # reitit (5)
- # shadow-cljs (14)
- # slack-help (10)
- # xtdb (6)
Good morning 🙂
Fashion trend question (may be a bit silly): When you do a (ns ... (:require [clojure.string :as _]))
, what alias do you usually use? ClojureDocs use str
, but there’s already a str
function in clojure.core
. string
works, but seems to be too long…
I’ve seen/used str
, s
and string
. I think string
is the most solid - str
(kind of) shadows, as you say, and s
is too short.
I’ve learned not to worry as much as I used to about it 🙂 But it would be neat if there were “standards” so that you could adhere to them without a second thought.
yes, I believe there is no absolute right answer in this case, and that’s why it is “Fashion”
str. There is no shadowing b/c namespace and fns are in different "domains".
I agree with Jakub.
I’d use str
as I think it is fine to have a namespace and a function having the same name. Clojure knows the difference.
I know that there’s no technical shadowing, but I still prefer not having two things with the same name, if it can be trivially avoided.
oh @U0AQ3HP9U you stole my line 😅
I do think that avoiding “collision that ain’t technically a collision” is more for benefit of beginners who may not know the details of clojure in and out
(although in a coding guideline that fact should probably be mentioned somewhere to clear the air)
Since I work with @jakub, str
, but ai should also plug that we use superstring
rather than clojure.string
#solidarity :fist:
@U0522TWDA that’s a TIL… you learn something new everyday, I suppose 👍
@U04V5VAUN wait, that picture in the github readme of superstring
… looks like some super-advanced pure math (I’m a math major) - algebraic geometry or some string theory stuff?
(I vaguely remember the same/similar photo hang on the wall of the math department I studied in)
we use string
and we have a kondo rule that warns if you use anything else!
@U0509NKGK what does that look like? (I'm thinking it might be handy to keep some aliases consistent across namespaces and projects)
https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#consistent-alias
I just use whatever the code base I'm working on uses. When writing new code, I`ve typically used string
but I'm not married to it and am also totally ok with str
.
>
It is poor form to (:use clojure.string). Instead, use require
> with :as to specify a prefix, e.g.
>
> (ns your.namespace.here
> (:require [clojure.string :as str]))
our team argued about it about once a year until someone lost their temper with it and added a kondo rule and refactored all the code to match it 😂
There ain't no bikeshedding on this ranch, if you wanna bikeshed, you come bikeshed me!
Did you get a cookie?
Or is that an American thing?
Chocolate :-)
niceeeee
:saluting_face:
It is not the only reason I keep coming there.. 😅
I would consider it for a chocolate.... it is just that they don't want my blood (and I'd probably faint as well)
I tried to give blood once (in my yoof) and I nearly passed out, that was before they even took blood!
Avoid Transylvania then 🧛
morning
So, I got this idea while listening to Software Disrupted about an inferred type system: My preferred type system is basically coding in Clojure as today, but then when I’m “done” or I feel certain about my data structures, it would be nice to sprinkle som types on it. But that retro fitting process is a bit cumbersome. But what if you could do something like:
(s/def ::user any?)
(s/fdef foo :args (s/cat :user ::user))
(defn foo [user] ...)
And then by magic ie static analysis have a compiler figure out what constitutes a user.
The trick of course being that you have many fns which take a user
as an arg, and that those fns in turn pass the user around to other fns which may or may not be speced.
So for instance if I said in my foo
fn:
(defn foo [{:keys [:name] :as user}]
(println "This user has name" name "and email" (:email user)))
The inferring type system would understand that the user spec should contain both a :name
and an :email
clj-kondo has a simple type system and malli is able to spit out the configuration for that, based on its own format
Ask and ye shall receive 🙏