Fork me on GitHub
#clojure-europe
<
2021-12-10
>
dharrigan06:12:07

Good Morning!

pez07:12:34

Morning. I feel I am doing something wrong making a private function public in order to test it.

kardan07:12:53

Maybe this is super bad, but I stopped using private functions for that reason 🙀

1
pez07:12:31

You lose some readability then. It’s nice to see right there that it is not meant for outside consumption.

kardan07:12:40

I separate by namespace with one “API” namespace

1
kardan07:12:53

But it’s becomes a bit of namespace explosion

kardan07:12:00

So not a panacea

pez07:12:11

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.

👍 3
kardan07:12:47

He’s the dude

pez07:12:22

I am using an impl sub-namespace and this was functions down there. I should slap an API namespace on them for the lols. 😃

reefersleep08:12:24

It’s funny how Clojure puts such an emphasis on immutability, yet is crazy malleable.

reefersleep08:12:22

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 🙂

pez08:12:44

The data is immutable, the program is mutable. 😃

reefersleep08:12:57

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.

reefersleep08:12:13

don’t recall the exact use case

dharrigan08:12:26

Another tip, if you have a private def is to altermeta

dharrigan08:12:36

;; Make it available for testing...
(alter-meta! #'sut/transformed-default-notifications dissoc :private)

reefersleep08:12:46

of course 🙂

reefersleep08:12:55

Private? I don’t think so

reefersleep08:12:24

if you don’t want your stuff to be public, don’t write it 😛

pez08:12:08

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.

👍 1
simongray09:12:20

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.

simongray09:12:50

just my €0.02

borkdude09:12:15

Other conventions include ^:no-doc and ^:skip-wiki

borkdude09:12:47

or just "implementation detail" in the docstring, also starting the function name with a dash is sometimes used: -foo-bar

vemv08:12:47

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

pez08:12:40

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.

vemv08:12:40

> 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 😇

practicalli-johnny10:12:40

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.

vemv13:12:52

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.

practicalli-johnny13:12:46

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

pez16:12:44

Brittleness means “easily breaks”, right? 😃 Which I don’t think goes for tests of pure functions.

pez16:12:58

In any case. I am pretty sure I want the unit tests that led to the thread start here.

borkdude07:12:52

@pez calling it via #’foo should work even if it’s private

kardan07:12:24

Good morning

thomas08:12:07

TGIF!!!!

☝️ 1
javahippie09:12:04

Is it pronounced “TEGIFF” or “TEJIFF”?

reefersleep09:12:44

good morning!

simongray10:12:22

“Thanks JPEG!”

otfrom10:12:18

TPNG for the Free Software types

2
genRaiy11:12:22

rong dooming

genRaiy11:12:38

when you're incorrect to be pessimistic in the morning

pez11:12:13

I’m starting to suspect you are not randomizing these. 😀

genRaiy11:12:43

the joy of randomness 🙂

genRaiy11:12:51

mostly saying FFS about FFI today

borkdude12:12:38

New blog post about clojure.spec.alpha compatibility with #babashka! https://blog.michielborkent.nl/using-clojure-spec-alpha-with-babashka.html

😎 2
thomas13:12:31

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?

thomas14:12:33

This could include consultants etc.

thomas14:12:48

we seem to have created a bit of a mess in this respect... but have no clue what the best practices are.

thomas14:12:46

and I certainly don't understand it all, how all these things relate to each other (IAM/Orgs).

practicalli-johnny10:12:40

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.