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
mccraigmccraig 2021-03-19T07:07:53.029300Z

månmån

djm 2021-03-19T07:16:49.029500Z

👋

dharrigan 2021-03-19T07:35:45.029700Z

Good Morning!

dharrigan 2021-03-19T08:54:08.030100Z

So, I saw the news about the new feature for clojure 11. Not sure I completely grok it

2021-03-19T09:10:45.031900Z

It just means you don’t need to do the apply concat hack if you need to apply a map of options to a function that was written to take kwargs

dharrigan 2021-03-19T09:17:21.032500Z

Thank you. I think I'll need to see more code examples. I'll have a look around.

2021-03-22T08:04:39.050500Z

Yeah I suspected that might be a motivating reason behind the change too

seancorfield 2021-03-22T11:30:59.052700Z

@rickmoynihan Apparently not: I asked Alex and he said it wasn’t — it’s more a case of this is how they felt it should have been done in the first place 🙂

2021-03-22T11:37:49.052900Z

I saw he’d made a similar comment on reddit (about this is how they always should have been); can’t remember if I wondered that before or after reading it… either way interesting to hear it’s just coincidence. :thumbsup:

dharrigan 2021-03-19T09:18:16.033500Z

as a side note, I have no idea the algorithms in play at the BBC news site, but embedding David Velez, CEO of Nubank into an article about employee burnout, doesn't seem quite right...

dharrigan 2021-03-19T09:18:18.033700Z

<https://www.bbc.co.uk/news/business-56452494>

2021-03-19T09:21:31.033800Z

Prior to this, if you a have a function like this:

(defn foo [arg1 &amp; {:as kwargs}] [arg1 kwargs])
You’d could use it like this:
(foo 1 :a "a" :b "b")
However the problem is if you have those args :a "a" :b "b" in a map, you’d have to have to call it more like this:
(let [opts {:a "a" :b "b"}] 
   (apply foo 1 (apply concat opts)))

2021-03-19T09:22:56.034100Z

This led to kwargs being a real annoyance. Best practice was don’t use them, except for functions that are only intended to be used at a REPL; and in macros.

2021-03-19T09:25:24.034300Z

However, I’m still not sure this should change the best practice advice. kwargs still make calling/usage inconsistent, and it makes it hard to know when reading the code if the args are a map of opts or positional parameters etc.

2021-03-19T09:27:11.034700Z

For the sake of two extra characters of noise for callers, it’s pretty pointless. i.e. This: (foo 1 :a "a" :b "b") vs: (foo 1 {:a "a" :b "b"})

dharrigan 2021-03-19T09:29:49.034900Z

I see. Digesting...

2021-03-19T09:30:10.035100Z

So I’m glad to finally have a nicer way to apply opts in the few places that kwargs are used in functions I need to use without using the apply concat trick. But I worry fixing this may make the use of kwargs more common.

2021-03-19T09:32:10.035300Z

Also worth noting that this change applies to destructuring everwhere, so not just kwargs. Though I think any usecases for that are questionable, and I think you’d be better being explicit.

alexlynham 2021-03-19T09:37:08.035500Z

morning

dharrigan 2021-03-19T09:39:35.035600Z

So, basically, it shoves whatever isn't a positional parameter into a map

thomas 2021-03-19T09:43:01.035900Z

moin moin

jiriknesl 2021-03-19T09:44:22.036100Z

Morning

2021-03-19T09:52:01.036200Z

kwargs do yes… They’ve been in clojure for a long time… I can’t recall which version they were introduced it was that long ago.

danm 2021-03-19T10:23:18.036700Z

Morning

danm 2021-03-19T10:25:19.036800Z

Having done a lot of Python recently, I tend to prefer explicit kwargs over positional params. If a fn only has 1 or 2 args then sure, but much more than that and I want them explicitly named not rely on remembering/looking up the order, especially in a weakly-typed language

danm 2021-03-19T10:26:03.037Z

I can pretty much guarantee that was a choice by someone editorial, not a machine-led decision for 'related content'

dharrigan 2021-03-19T10:28:00.037200Z

Bizarre choice then 🙂

alexlynham 2021-03-19T10:40:44.037400Z

why is it weird?

dharrigan 2021-03-19T10:45:39.037600Z

The video clip doesn' talk whatsoever about the contents of the article

dharrigan 2021-03-19T10:45:41.037800Z

it's out of place

dharrigan 2021-03-19T10:46:04.038Z

The video clip is a short 30 second clip of him talking about how he started to form NuBank

dharrigan 2021-03-19T10:46:42.038800Z

You would have imagined that if there was a video clip, in an artricle about employee overworking, then the video would be, maybe an interview of someone talking about burnout.

mccraigmccraig 2021-03-19T11:16:37.039Z

i also prefer named args over many positional args - but make them a map, not kwargs - you are often going to end up building the args as a map anyway, adding things to it, taking them away to pass it on... kwargs make life awkward

dharrigan 2021-03-19T11:18:36.039200Z

is kwargs the :as .... part?

2021-03-19T11:18:42.039400Z

Yup I agree named arguments are better than positional arguments, once you get past 3 options. Indeed Rich has spoken about this many times in the past.

2021-03-19T11:18:51.039600Z

No its the &amp; {} part

dharrigan 2021-03-19T11:19:03.039800Z

Ah, I dont think I've ever used that

2021-03-19T11:19:04.040Z

&amp; switches it to variable arity

2021-03-19T11:19:22.040200Z

&amp; with a map after it roles the variable arity into a map.

dharrigan 2021-03-19T11:19:24.040400Z

In my code, I have a few positional, then my convention is the last var may be a map :

2021-03-19T11:20:22.040700Z

yes that’s almost always the best way to do it

2021-03-19T11:21:02.040900Z

well depending on whether you need those positional args in the first place

mccraigmccraig 2021-03-19T11:21:48.041100Z

awkward when you want to give the options to a sequence consuming fn ... in which case i seem to vacillate between first and second to last place

2021-03-19T11:22:41.041300Z

yup that’s definitely true -&gt; and -&gt;&gt; are always worth considering to. I find much of this also depends on whether you’re app or library code.

Eamonn Sullivan 2021-03-19T13:12:19.041600Z

@dharrigan, what video are you referring to with the employee burnout? There is actually an algorithm nowadays, so it would be good to show someone where it has gone wrong.

Eamonn Sullivan 2021-03-19T13:14:06.042Z

Oh, I see it. Sorry, not in the thread.

Eamonn Sullivan 2021-03-19T13:18:23.042200Z

:face_with_rolling_eyes: Just happens to be tagged with "banking" too. The kids they have running the editing desks these days...

jasonbell 2021-03-19T15:47:56.042500Z

Morning

danm 2021-03-19T16:32:41.042900Z

Anyone got any tips for tracking down a StackOverflow? 😉

danm 2021-03-19T16:33:34.044100Z

Like, I can see from what I have got that it's probably related to a lazy-seq, potentially a fn recursively calling itself, but there's a lot of code to look through here trying to find that...

seancorfield 2021-03-19T16:40:32.044200Z

We have 35 instances of &amp; { in our codebase at work so this feature will allow us to clean up some calls. I wish it had been fixed a long time ago, so a lot of the shift from kwargs to map args would not have happened.

seancorfield 2021-03-19T16:41:45.044400Z

It’ll be interesting to see whether it causes a swing back to kwargs. I think one of the reasons for making the change now is the introduction of -X which essentially takes kwargs on the command-line but massages them into a hash map internally. This will allow you to write your exec-fns as if they were taking kwargs from the command line.

alexlynham 2021-03-19T16:46:07.044600Z

wait, didn't @mccraigmccraig have that exact bug yday?

mccraigmccraig 2021-03-19T17:05:25.045900Z

mine was a promise-returning fn (with callbacks on a threadpool) which was recursively calling itself... it ate the world trying to create an infinite promise-chain and crashed the vm

dharrigan 2021-03-19T17:12:24.046200Z

you promise too much @mccraigmccraig!

1
1
mccraigmccraig 2021-03-19T17:21:55.047100Z

are you actually seeing a stacktrace @carr0t?

danm 2021-03-19T18:30:21.047900Z

I am seeing a stacktrace which is a long loop of the same calls, all in clojure.core. Looks like some errors with handling of a lazy-seq/concat

danm 2021-03-19T18:30:43.048400Z

I have just found out about a JVM arg that prevents stacktraces being truncated though, so I'm going to try that

danm 2021-03-19T18:43:25.049200Z

Oh boo, -XX:MaxJavaStackTraceDepth=-1 doesn't seem to work on OpenJDK 12. I'll try with just the max it can go to