clojure-uk

A place for people in the UK, near the UK, visiting the UK, planning to visit the UK or just vaguely interested to randomly chat about things (often vi and emacs, occasionally clojure). More general the #ldnclj
Hugh Powell 2020-09-24T00:44:08.016600Z

Yep, I'm with @seancorfield and @mccraigmccraig.

codeasone 2020-09-24T04:46:59.000300Z

Morning!

codeasone 2020-09-24T04:48:15.000400Z

đź‘Ť or (subject under test) more generally

1
jiriknesl 2020-09-24T05:03:28.000700Z

Morning

mccraigmccraig 2020-09-24T05:45:27.001300Z

mĂĄnmĂĄn

dharrigan 2020-09-24T05:46:15.001500Z

Morning!

dharrigan 2020-09-24T05:46:40.002100Z

Thanks @seancorfield @mccraigmccraig et al.

djm 2020-09-24T05:52:52.002400Z

đź‘‹

agile_geek 2020-09-24T06:42:57.002600Z

Bore da :welsh_flag:

dominicm 2020-09-24T07:13:10.002900Z

Morning

malcolmsparks 2020-09-24T08:03:23.003600Z

Morning

alexlynham 2020-09-24T08:06:01.003700Z

morning

alexlynham 2020-09-24T08:23:42.003800Z

late to the party but always :as so you have a specific namespace

alexlynham 2020-09-24T08:23:54.003900Z

except in some very particular cases

dharrigan 2020-09-24T08:46:27.004200Z

there's always room for one more at the party

dharrigan 2020-09-24T08:46:59.004900Z

the continuous never-ending, no-need-to-be-socially-distant-or-wear-a-face-mask clojure party 🙂

dharrigan 2020-09-24T09:42:47.006500Z

I have another good practice question, do you mark functions as private (in their namespace) or just don't bother?

2020-09-25T08:13:42.019900Z

@seancorfield, it’s a fair assumption, but in the past I’ve found lower-level functions I cannot use because they’re scoped private, presumably because the author didn’t think they’d be useful. It’s not always possible to anticipate the API that library users will need – often they don’t know until they start digging, or hit on a problem which means they can’t use the API as intended. OS maintainers are free to put out whatever they want of course, and there’s always a way round – please don’t take this as criticism of all the great work you’ve done! But for the sake of convenience I would eschew private in my libs unless I thought the vars were unquestionably off limits.

dominicm 2020-09-25T10:58:00.027Z

I feel like this conversation is potentially across purposes. I private functions because I have no intention of retaining or supporting them. Both answers given are potentially correct, so there's actually an additional distinguishing dimension.

đź‘Ť 1
Adrian Smith 2020-09-25T12:25:29.029600Z

It's a weird thing to think about, I think most people's intention is actually to try and tell you the functions they expect you to use, but when you see a private function it often won't explicitly tell you what function you should be using Maybe it'd be better to think about a mechanism for promoting functions rather than demoting functions

seancorfield 2020-09-25T16:25:23.041900Z

@lsnape As an OSS maintainer, if someone decides to start using a private var and doesn't create an issue asking for it to be made public, I'm not going to be very sympathetic if I refactor the function away or change its signature (or even its behavior) and break their code 🙂

seancorfield 2020-09-25T16:26:00.042100Z

OTOH, I am perfectly happy to consider an issue requesting a private var be "promoted" to part of the API.

dominicm 2020-09-25T17:48:57.057100Z

I think the question is why the structure of the API even makes it a problem. There's usually a mismatch in either design or problem being solved.

seancorfield 2020-09-25T18:02:49.057600Z

Definitely. If I "made a mistake" and made something private that left the API lacking, I'm happy to fix it. If the private function is truly an implementation detail then I need to figure out what the API should so that functionality is exposed officially, in a supportable manner.

thomas 2020-09-24T09:45:58.006700Z

moin moin

mccraigmccraig 2020-09-24T09:48:03.007200Z

rarely @dharrigan, but occasionally it seems like the right thing to do

dharrigan 2020-09-24T09:49:01.007400Z

I'm feeling the same 🙂 Currently, nothing of mine is "private"

mccraigmccraig 2020-09-24T09:49:37.007600Z

e.g. i marked a fn which implements an extend protocol method fn private yesterday... but i think that's the only private fn in the whole project

reborg 2020-09-24T09:53:10.007900Z

As the project grows in size, I find marking fns as private essential. That tells me if I should expect clients of the fn outside the ns but in the same project. I use another practice to mark fn that are also used outside the project. I create a wrapper for them in a specific ns meant as public facing API (for example core). If the function is there, it’s used by external dependencies and should be treated accordingly to allow graceful upgrade.

dharrigan 2020-09-24T09:55:31.008200Z

that's an interesting approach 🙂

reborg 2020-09-24T09:56:00.008400Z

I noticed this “more formal” approach starts to be required with team of 15-20 people working on mutually integrating projects

dharrigan 2020-09-24T09:56:14.008600Z

when doing private, do you prefer (defn-...) or (defn ^:private ....)?

reborg 2020-09-24T09:56:44.008900Z

If that’s not your case… don’t bother, all public! :)

reborg 2020-09-24T09:56:53.009100Z

Normally defn- which is shorter

alexlynham 2020-09-24T10:00:45.009300Z

I tend to mark things as private a fair bit, but often find that I eventually end up unmarking a lot of them cos they need to be used

âž• 1
reborg 2020-09-24T10:01:52.009500Z

Other good scaling projects conventions: put docstrings in namespaces, kill utils.clj ruthlessly, don’t mark fn public because you want to test them ;)

dharrigan 2020-09-24T10:02:11.009700Z

all very interesting 🙂 I like to ponder on what people do and see if I can use/adapt/ignore 🙂

reborg 2020-09-24T10:04:35.009900Z

again… formality/conventions bring value when scaling, it has a price in the small. As always, tradeoffs.

dominicm 2020-09-24T10:48:10.010200Z

I bet this varies a lot on how you structure your code. If it's more like a series of libraries which are being composed together, then there's a lot more private vars.

dominicm 2020-09-24T10:48:27.010400Z

The 15-20 heuristic as a point when libraries start happening is a good link.

2020-09-24T11:20:36.010800Z

Morn'

2020-09-24T14:04:53.010900Z

In the past I've tried to use functions in libraries, only to find the author made them private. Very frustrating! However for non-library projects i have found them useful

seancorfield 2020-09-24T15:51:44.011300Z

I started off obsessively marking everything private (with defn-) because of my OO background. Then I gradually shifted to having everything public so client code could call anything and it was all easier to test. Like @reborg as our project at work has grown, I've gone back to making everything private unless it is a documented part of the API because my linter can tell me if a private Var is unused which helps with maintenance in a large codebase. I also have clj-kondo set to flag missing docstrings on public Vars -- again, a nod to the API-ness of such things.

seancorfield 2020-09-24T15:52:55.011500Z

In my OSS libraries in particular, keeping things private unless they're part of the documented API makes life a lot easier -- for me as maintainer and for my users since they can stick to reading the API docs in general and not have to go grubbing around in the code.

dharrigan 2020-09-24T16:38:33.011800Z

that's very interesting too. Do you still favour (favor? 🙂 ) defn- over ^:private?

seancorfield 2020-09-24T16:49:42.012Z

defn- and def ^:private

seancorfield 2020-09-24T16:50:05.012200Z

(after all, defn- is built-in and shorter than defn ^:private)

dharrigan 2020-09-24T16:50:31.012400Z

🙂