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
jiriknesl 2020-09-17T04:24:36.331200Z

Good moaning https://i.pinimg.com/736x/42/c5/94/42c594705b5b803f4d223400e625f999.jpg

dominicm 2020-09-17T05:31:19.331500Z

Morning

dharrigan 2020-09-17T06:17:12.331800Z

Good Morning!

alexlynham 2020-09-17T07:35:25.331900Z

morning

alexlynham 2020-09-17T07:36:03.332Z

yarn isn't really needed now that npm has a native runner and lockfiles afaict

alexlynham 2020-09-17T07:36:19.332100Z

though maybe i'm missing a trick :)

2020-09-17T07:44:32.336900Z

When I did front end js agency work npm was a nightmare… But I’ve been out of that world for many years, and we’re currently using yarn in combination with shadow-cljs. However a colleague of mine who is in the know wrt js matters, by pure coincidence mentioned to me yesterday that npm was very deserving of its bad rep, but they eventually fixed the problems and is pretty good these days. Hence I think it’s one of those things where peoples perspective is coloured by when they last used it.

dharrigan 2020-09-17T08:13:32.341800Z

Question. Let say you receive a request that contains a code. That value is used to determine which code path to follow. Each code path could potentially invoke 1 of a number of possible calls, but only some are valid for a particular value. In Java, I would have an interface that has this set of possible methods, with the concrete implementations either providing the functionality, or returning an UnsupportedOperationException (or a null value) (keeping it simple, not taking about an abstract partial implementation). At runtime I would invoke the particular concrete implementation depending upon the value I receive, assured that as the interface is being implemented, the method must exist on the implemenation (the method may or may not return a result). In Clojure, would a multimethod suffice, or would I look to use Protocols (not something I've used before)

dharrigan 2020-09-17T08:14:45.342600Z

Looking to keep it simple to reason about and extensible.

seancorfield 2020-09-17T08:31:48.344300Z

Protocols are the closest to Java interfaces (and implementing classes) and they'll dispatch on the type of the first argument (the "object type" in Java).

seancorfield 2020-09-17T08:32:07.344700Z

Multimethods can dispatch on anything.

seancorfield 2020-09-17T08:32:29.345100Z

When you say "a request that contains a code", what exactly do you mean?

seancorfield 2020-09-17T08:32:52.345600Z

What is that code? Can it have multiple types, or just multiple values of the same type?

dharrigan 2020-09-17T08:39:15.346100Z

just a code, like "TISITA" which means something to us internally

seancorfield 2020-09-17T08:40:49.348100Z

So how would you have interface / implementation in Java based on that?

dharrigan 2020-09-17T08:40:56.348300Z

Just writing that 🙂

dharrigan 2020-09-17T08:40:58.348500Z

A moment

seancorfield 2020-09-17T08:41:45.349500Z

(I'm expecting a factory method or even a factory builder class thingy at this point 😐 )

dharrigan 2020-09-17T08:44:49.352500Z

Basically I have a set of customers which can grow. Each customer is allowed to perform a series of operations, let's say "eat", "sleep", "drink". However, not all customers need to "eat". But they may do in the future. So, I want to design something that says, if you are onboarding a new customer, they all have to adhere to "eat" "sleep" "drink", but maybe it might take some time for them to respond to the "eat" request, so just return nil for now. Therefore, as the request comes in (from the API) and I see, ah! this is Customer A, I still want to invoke "eat", but I don't really care if it returns something or nothing right now.

dharrigan 2020-09-17T08:45:55.353900Z

(think that "eat" is gaining access to their database to pull values out of their system - but takes them ages to do setup the right structure for me to interrogate their db)

seancorfield 2020-09-17T08:45:56.354Z

So you either have to create a new "type" per customer or have some sort of double dispatch that works dynamically.

dharrigan 2020-09-17T08:46:12.354200Z

right right.

dharrigan 2020-09-17T08:46:19.354400Z

which makes more sense?

seancorfield 2020-09-17T08:46:51.355Z

Creating a new "type" for every customer feels... awful... I mean, that's why I don't do C++/Java any more!

seancorfield 2020-09-17T08:48:27.356900Z

So I would probably lean toward something more pluggable, and have a hash map per customer with :eat, :sleep, :drink keys and if they are implemented, the value would be a function (or a qualified symbol that resolved to a function) and if they are not implemented, the key could just be omitted.

alexlynham 2020-09-17T08:48:42.357200Z

it's pretty much as you say @rickmoynihan

alexlynham 2020-09-17T08:48:47.357400Z

it was bad, then they fixed it

seancorfield 2020-09-17T08:48:47.357500Z

(when-let [f (:foo customer)]
  ((requiring-resolve f) customer :or :whatever))

alexlynham 2020-09-17T08:48:49.357600Z

now it's good

dharrigan 2020-09-17T08:49:21.358Z

right right. thinking...

seancorfield 2020-09-17T08:50:09.358900Z

The nice thing about a hash map with qualified function symbols is you can easily serialize that -- to a file or DB or over the wire or whatever.

dharrigan 2020-09-17T08:50:15.359100Z

never used requiring-resolve before...

dharrigan 2020-09-17T08:50:18.359300Z

a mment

dharrigan 2020-09-17T08:50:19.359500Z

door

seancorfield 2020-09-17T08:50:42.359600Z

It was new in 1.10

alexlynham 2020-09-17T08:51:08.359800Z

sorry dharrigan to be memeing around a serious conversation but i always think this when js comes up haha

dharrigan 2020-09-17T08:51:46.360200Z

btw, you're up late Sean

seancorfield 2020-09-17T08:53:37.361200Z

Yeah, rough day. We spent 3+ hours at the emergency vet with one of our cats tonight (and dropped $5,000 on it) so I'm trying to chill enough to go to bed. Already two beers in since I got home...

seancorfield 2020-09-17T08:54:39.362300Z

(This is a cat we spent $10,000 on four years ago for open chest surgery to remove a tumor -- we think maybe the tumor is back so we're not even sure we'll get him back from this latest vet visit)

dharrigan 2020-09-17T08:54:49.362500Z

oh dear

dharrigan 2020-09-17T08:55:00.362700Z

I hope it recovers well

dharrigan 2020-09-17T08:56:38.364300Z

is :foo in this, my :eat in my discourse?

seancorfield 2020-09-17T08:56:38.364500Z

Thanks, but we're not very hopeful. We were very lucky the tumor was operable before -- they happened to have access to a very special feline surgeon -- but the initial evaluation this time shows "very abnormal heart shape" and hyper-inflated lungs so... 😞

1😢
seancorfield 2020-09-17T08:57:27.365400Z

He's 15, nearly 16, so we don't want to put him through such invasive surgery again. He barely recovered last time.

seancorfield 2020-09-17T08:58:08.365800Z

(but once this second beer is gone, I'm off to bed... and it's nearly gone)

seancorfield 2020-09-17T08:58:24.365900Z

Yeah, or :sleep or :drink

seancorfield 2020-09-17T08:58:39.366100Z

Or :implement-your-f'ing-database 🙂

dharrigan 2020-09-17T08:58:46.366300Z

neat

dharrigan 2020-09-17T08:59:04.366500Z

ah stand up

thomas 2020-09-17T09:01:07.366800Z

morning

seancorfield 2020-09-17T09:14:26.367Z

(beer's empty, bedtime!)

dharrigan 2020-09-17T09:14:37.367200Z

thanks sean

dharrigan 2020-09-17T09:14:49.367600Z

I’m going to ponder on what you’ve said and maybe have more questions later 🙂

dharrigan 2020-09-17T09:14:51.367800Z

ttfn!

2020-09-17T09:23:03.367900Z

and you can get it to implement a protocol too

yogidevbear 2020-09-17T09:41:02.369100Z

Morning. Sorry to hear about you feline friend Sean 😿

dharrigan 2020-09-17T09:51:32.369600Z

Playing around with requiring-resolve. It seems another way of doing dynamic dispatch, akin to a multimethod

alexlynham 2020-09-17T10:08:48.369700Z

@dharrigan for what you describe I'd literally just do a multimethod

1☝️
alexlynham 2020-09-17T10:09:02.369800Z

probably also a good place to use a variant

alexlynham 2020-09-17T10:09:33.369900Z

[:type/of/thing {:hash-map-representation-of-thing "will work i think"}]

alexlynham 2020-09-17T10:09:47.370Z

arbitrarily extendable

alexlynham 2020-09-17T10:10:11.370100Z

and you can validate with a spec or schema that has an enum/set of the :type/of/things that you allow

2020-09-17T10:22:23.374500Z

Yeah, @dharrigan personally I’d be careful with using requiring-resolve after system instantiation. Loading namespaces and their dependencies can be side effecting, so it’s good to know when things are required. Also might be worth mentioning you can use integrant to ensure each customer has the appropriate set of f ’s, you can then optionally use ig/load-namespaces to essentially do the requiring resolve; but essentially move that call to instantiation time rather than having it be at runtime or on-demand.

alexlynham 2020-09-17T10:23:14.375Z

ooh i hadn't thought of that

alexlynham 2020-09-17T10:23:23.375100Z

gpwm

2020-09-17T10:24:56.376400Z

integrant is pretty great at letting you configure a base config of wiring, and then having config per customer, all as edn.

2020-09-17T10:25:51.376700Z

?

dharrigan 2020-09-17T10:25:53.376900Z

I use juxt clip instead of integrant :)

dharrigan 2020-09-17T10:26:33.377200Z

but it would do the same thing

2020-09-17T10:27:18.377600Z

yeah it should support a similar setup

2020-09-17T10:28:26.378100Z

Looks like it also does the requiring-resolve

alexlynham 2020-09-17T10:36:40.378200Z

good point well made

dominicm 2020-09-17T11:44:12.380Z

I think this is what gets me about the js/node ecosystem: https://clojurians.slack.com/archives/C03RZGPG3/p1600274375276100 That's where my problems stem from. Lock files are great, but this problem can't be solved on stack overflow.

alexlynham 2020-09-17T12:03:11.380200Z

:woman-shrugging:

alexlynham 2020-09-17T12:03:28.380300Z

i very rarely have to interact with the community as a dev

alexlynham 2020-09-17T12:04:29.380400Z

the culture hasn't generally affected me other than the occasional big f-up that's obv affected all node projects, but no different to heartbleed or whatever it might be where i've had to patch servers

alexlynham 2020-09-17T12:04:32.380500Z

these things happen

alexlynham 2020-09-17T12:04:54.380600Z

and better node having that problem than e.g. the white supremacy problem in haskell

alexlynham 2020-09-18T10:48:24.009800Z

Look up the stuff around lambda conf, one of the main alt right 'thinkers' is/was big in haskell and we've had our fair share of edgy stuff from that quarter as event organisers. Like most things it's a few bad apples but does seem to be more common in haskell and scala. Although the uncle bob thing is bringing it home to roost in clj land now as well.

joetague 2020-09-18T12:35:51.010200Z

Thanks Alex. I was somewhat aware of Lambda conf issues and yeah I see issues relating to Bob Martin as well 😕

alexlynham 2020-09-17T12:05:04.380700Z

but i take yr point

joetague 2020-09-17T13:23:40.382Z

I’ve not heard that about Haskell before. Could you share a source?

dominicm 2020-09-17T14:12:37.384300Z

@alex.lynham oh yeah, it affects everyone in node. But node users seem to enjoy rewriting everything every few months to use the latest version of a library. Power to them, but it's not for me.

2020-09-17T14:49:25.385900Z

grr; there's been a Spitfire circling overhead with > Thankyou NHS painted onto its wings. People seem to be going into paroxysms of ecstacsy, But it doesn't seem to me like its doing much good for anybody

2020-09-17T14:49:36.386300Z

I mean the pilot is having fun, obviously

2020-09-17T14:49:47.386600Z

but that's it

2020-09-17T14:50:16.387200Z

Is it just that I've completed my transformation into a Miserable Old Git

dharrigan 2020-09-17T14:51:29.387800Z

We're very inclusive 🙂

2020-09-17T14:52:41.388400Z

the best thing about the Spitfire aeroplane is that it was given a cool name

2020-09-17T14:53:20.388700Z

well and was very agile for its time I suppose

alexlynham 2020-09-17T15:28:48.389Z

it was, plus relatively cheap to build

alexlynham 2020-09-17T15:29:55.389100Z

a straw poll of my ex housemates (all doctors) suggests that they don't want thanks, they want people to vote out the tories and vote in a government that will fund the nhs

2020-09-18T08:27:03.008900Z

@alex.lynham Yeah, I felt I was one of the few people in the country who hated the clap for the NHS thing. Firstly the time genuinely didn’t suit as it was daughters bed time. However mainly I objected to the idea that NHS workers should be heroes. Not because they’re not deserving of the highest admiration; because they are, but because we shouldn’t expect and exert social pressure on them to risk their lives. It felt to me like the government encouraging the country to clap for them just enabled the government to not give them PPE, not give them pay rises, and generally treat them like dirt; but that’s ok because they’re heroes now!

2020-09-18T08:28:53.009200Z

I also know a few NHS workers who felt similarly; but the country clapping thing kinda silenced them on the issue.

alexlynham 2020-09-18T10:29:43.009400Z

Yeah what you say basically lines up with what my mates said. One was on an acute rotation where they were reusing PPE and he was very angry about it as you can imagine

alexlynham 2020-09-18T10:30:12.009600Z

Clapping doesn't solve chronic underfunding and government incompetence

1💯
2020-09-18T14:42:53.011Z

@jiriknesl: That’s just because we’re a first world country. Most developed economies should expect to be in the top 10% globally. If you compare us to developed economies it’s more complicated, but we typically don’t do better than mediocre, and tend to be towards the bottom of the pile for most metrics.

2020-09-17T15:50:56.389300Z

makes sense

Aron 2020-09-17T16:43:34.389400Z

I have not used gulp/grunt/fez/bower/ or any of these ever. 🙂 Not for production anyway.

mccraigmccraig 2020-09-17T16:53:47.389600Z

gulp was actually pretty nice (it uses an async streams and promises model i'm very familiar with from clojure), but we had to do some JSON->EDN conversion and doing anything with js datastructures is just awful

seancorfield 2020-09-17T19:10:00.389800Z

@dharrigan It's just a version of resolve that will require the ns of the name if it isn't already loaded. resolve turns qualified symbols into actual Vars.