This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-10
Channels
- # adventofcode (54)
- # announcements (30)
- # asami (13)
- # aws (10)
- # babashka (16)
- # babashka-sci-dev (44)
- # beginners (95)
- # calva (63)
- # clara (10)
- # clj-kondo (3)
- # cljfx (6)
- # cljs-dev (7)
- # cljsrn (1)
- # clojure (68)
- # clojure-europe (59)
- # clojure-nl (7)
- # clojure-norway (12)
- # clojure-spec (6)
- # clojure-uk (6)
- # clojurescript (4)
- # component (4)
- # conjure (5)
- # datomic (3)
- # deps-new (1)
- # events (4)
- # exercism (1)
- # figwheel-main (1)
- # fulcro (33)
- # gratitude (1)
- # improve-getting-started (3)
- # jobs (3)
- # lsp (5)
- # malli (10)
- # membrane (5)
- # music (3)
- # nextjournal (6)
- # off-topic (42)
- # pedestal (2)
- # polylith (14)
- # portal (11)
- # re-frame (42)
- # releases (3)
- # reveal (4)
- # shadow-cljs (62)
- # tools-build (1)
- # tools-deps (3)
- # web-security (1)
- # xtdb (3)
Morning. I feel I am doing something wrong making a private function public in order to test it.
You lose some readability then. It’s nice to see right there that it is not meant for outside consumption.
But asking in this fantastic channel helped. @U04V15CAJ’s tip to call it with #'foo
works perfectly. The function stays private and the linter is happy.
I am using an impl
sub-namespace and this was functions down there. I should slap an API namespace on them for the lols. 😃
It’s funny how Clojure puts such an emphasis on immutability, yet is crazy malleable.
I like both private fns and separation into private nses for clarity, even if the user can, in reality, reach in and grab whatever they want, and abuse it however they want 🙂
BTW, I think you can also use the #'foo
type of reference to ensure that you get the newest version of a function during development. I’ve had a situation or two where a direct reference netted me the old version.
don’t recall the exact use case
;; Make it available for testing...
(alter-meta! #'sut/transformed-default-notifications dissoc :private)
of course 🙂
Private? I don’t think so
if you don’t want your stuff to be public, don’t write it 😛
One use case is hot-reload in e.g. shadow-cljs. Remounting a dynamically updated change to a component won’t happen if you use the symbol.
Feels like we need a defimpl
or ^:impl
that produces suitable warnings as opposed to the hard line private functions. I am not totally against an impl namespace, but I feel that it is basically trying to fix things using the file system which just seems more like a hack. The good thing about private functions is that related code can live nearby and you lose this by putting things in an impl ns.
or just "implementation detail" in the docstring, also starting the function name with a dash is sometimes used: -foo-bar
I've done exactly as @U051F5T93 for a few years now in clj and I think my life has only gotten better :) I particularly like that skimming an "api" ns only has the relevant bits. I can jump-to-def for impl details if/when needed. Which is a pretty different experience from encountering a monolithic ns with api / impl details intermingled. Especially if I didn't author that ns - often I'll wonder "how do I read this", "where are the relevant bits", etc
Just checking. Having an api
namespace and having an impl
sub namespace is roughly the same thing, right? Else I am missing something. I have a project where we use #polylith and its insistence on interface
namespaces is pretty nice and also sounds similar to what you describe, @U45T93RA6.
> Having an `api` namespace and having an `impl` sub namespace is roughly the same thing, right? Yes. I actually try do both at the same time: have foo.api + foo.impl, with no naked foo. This way consumers can realise which one is the intended api, which perhaps foo or foo.core would not convey > I have a project where we use #polylith and its insistence on `interface` namespaces is pretty nice and also sounds similar to what you describe I also use Poly at work. Indeed it seems similar. It might be a slightly more coarse-grained building block: one pattern is only concerned with namespaces, while the other involves creating a deps.edn file, etc. I have codebases with say 20 impl.clj namespaces, if I were to add 20 deps.edn files, directory structures, etc I would give up 😇
No need to test private functions directly, when they get tested through the public functions that use them, often multiple times. Keeps the code simple and readable, with fewer brittle tests.
I disagree with that, private functions are often tasty, pure functions that are extremely simple to test. A deftest for them will look like a mapping of inputs to outputs. There's no possible brittleness in such a deftest. If it stops being useful you can just discard it. Brittleness comes from Java/Ruby-like patterns e.g. spies, mocks, etc; they're very literally complex because they tangle different defns, state, etc.
We seem to have a different perspective on brittleness. I am interested in testing the API of a namespace and not the implementation details. But this is software, so people are free to talk what ever approach they wish
Brittleness means “easily breaks”, right? 😃 Which I don’t think goes for tests of pure functions.
Is it pronounced “TEGIFF” or “TEJIFF”?
good morning!
New blog post about clojure.spec.alpha compatibility with #babashka! https://blog.michielborkent.nl/using-clojure-spec-alpha-with-babashka.html
Hi, we are struggling with AWS accounts/organisations/IAM and what ever else there is in that area... Any ideas where I can get help with this?
we seem to have created a bit of a mess in this respect... but have no clue what the best practices are.
and I certainly don't understand it all, how all these things relate to each other (IAM/Orgs).
No need to test private functions directly, when they get tested through the public functions that use them, often multiple times. Keeps the code simple and readable, with fewer brittle tests.