Fork me on GitHub
#clojure-uk
<
2020-09-17
>
dharrigan06:09:12

Good Morning!

alexlynham07:09:03

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

alexlynham07:09:19

though maybe i'm missing a trick :)

rickmoynihan07:09:32

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.

dharrigan08:09:32

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)

dharrigan08:09:45

Looking to keep it simple to reason about and extensible.

seancorfield08:09:48

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).

seancorfield08:09:07

Multimethods can dispatch on anything.

seancorfield08:09:29

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

seancorfield08:09:52

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

dharrigan08:09:15

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

seancorfield08:09:49

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

dharrigan08:09:56

Just writing that 🙂

seancorfield08:09:45

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

dharrigan08:09:49

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.

dharrigan08:09:55

(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)

seancorfield08:09:56

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

dharrigan08:09:12

right right.

dharrigan08:09:19

which makes more sense?

seancorfield08:09:51

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

seancorfield08:09:27

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.

alexlynham08:09:42

it's pretty much as you say @rickmoynihan

alexlynham08:09:47

it was bad, then they fixed it

seancorfield08:09:47

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

dharrigan08:09:38

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

seancorfield08:09:24

Yeah, or :sleep or :drink

seancorfield08:09:39

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

alexlynham08:09:49

now it's good

dharrigan08:09:21

right right. thinking...

seancorfield08:09:09

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.

Ben Hammond09:09:03

and you can get it to implement a protocol too

dharrigan08:09:15

never used requiring-resolve before...

seancorfield08:09:42

It was new in 1.10

alexlynham08:09:08

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

dharrigan08:09:46

btw, you're up late Sean

seancorfield08:09:37

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

seancorfield08:09:39

(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)

dharrigan08:09:00

I hope it recovers well

seancorfield08:09:38

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... 😞

😢 3
seancorfield08:09:27

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

seancorfield08:09:08

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

seancorfield09:09:26

(beer's empty, bedtime!)

dharrigan09:09:49

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

yogidevbear09:09:02

Morning. Sorry to hear about you feline friend Sean 😿

dharrigan09:09:32

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

seancorfield19:09:00

@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.

alexlynham10:09:48

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

☝️ 3
alexlynham10:09:02

probably also a good place to use a variant

alexlynham10:09:33

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

alexlynham10:09:47

arbitrarily extendable

alexlynham10:09:11

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

rickmoynihan10:09:23

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.

alexlynham10:09:14

ooh i hadn't thought of that

alexlynham10:09:40

good point well made

rickmoynihan10:09:56

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

dharrigan10:09:53

I use juxt clip instead of integrant :)

dharrigan10:09:33

but it would do the same thing

rickmoynihan10:09:18

yeah it should support a similar setup

rickmoynihan10:09:26

Looks like it also does the requiring-resolve

dominicm11:09:12

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.

alexlynham12:09:11

:woman-shrugging:

alexlynham12:09:28

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

alexlynham12:09:29

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

alexlynham12:09:32

these things happen

alexlynham12:09:54

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

joetague13:09:40

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

alexlynham10:09:24

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.

joetague12:09:51

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

alexlynham12:09:04

but i take yr point

dominicm14:09:37

@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.

Ben Hammond14:09:25

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

Ben Hammond14:09:36

I mean the pilot is having fun, obviously

Ben Hammond14:09:47

but that's it

Ben Hammond14:09:16

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

dharrigan14:09:29

We're very inclusive 🙂

Ben Hammond14:09:41

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

Ben Hammond14:09:20

well and was very agile for its time I suppose

alexlynham15:09:48

it was, plus relatively cheap to build

alexlynham15:09:55

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

jiriknesl06:09:01

Isn’t the UK healthcare funding in top 10 % worldwide in almost any measurable way?

rickmoynihan08:09:03

@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!

rickmoynihan08:09:53

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

alexlynham10:09:43

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

alexlynham10:09:12

Clapping doesn't solve chronic underfunding and government incompetence

💯 3
rickmoynihan14:09:53

@U061C5DAA: 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.