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-11-16T05:55:22.493300Z

Good morning

djm 2020-11-16T07:03:43.493500Z

👋

dharrigan 2020-11-16T07:24:12.493700Z

Morning!

rlj 2020-11-16T08:48:03.494Z

Mornin

mccraigmccraig 2020-11-16T08:51:35.494300Z

månmån

alexlynham 2020-11-16T08:54:19.494400Z

morning

Jakob Durstberger 2020-11-16T09:04:35.494700Z

morning

joetague 2020-11-16T09:14:33.495100Z

morning

yogidevbear 2020-11-16T09:17:53.495400Z

o/

2020-11-16T09:22:11.495700Z

\o morning

2020-11-16T09:29:44.496Z

morning

2020-11-16T09:40:59.496300Z

Morning

rlj 2020-11-16T11:12:24.498600Z

What do people think about re-using (shadowing) names in lets? I've got into the habit of naming a variable after the function that produced it. It seems 'cleaner' (no extra arbitrary names) but you can get some confusing errors if you slip up.

rlj 2020-11-16T11:12:56.499300Z

;; reuse name
(let [age-in-years    (age-in-years person (now))
      body-mass-index (body-mass-index person)
      smoker?         (smoker? person)]
  (risk-of-heart-disease age-in-years body-mass-index smoker?))

;; or... arbitrary abbreviations
(let [age    (age-in-years person (now))
      bmi    (body-mass-index person)
      smokes (smoker? person)]
  (risk-of-heart-disease age bmi smokes))

;; or... systematic prefix (something like a-, an-, the-, is-)
(let [the-age-in-years    (age-in-years person (now))
      the-body-mass-index (body-mass-index person)
      is-smoker           (smoker? person)]
  (risk-of-heart-disease the-age-in-years the-body-mass-index is-smoker))

;; or... systematic prefix (based on 'p' for person, in this case)
(let [p-age-in-years    (age-in-years person (now))
      p-body-mass-index (body-mass-index person)
      p-smoker?         (smoker? person)]
  (risk-of-heart-disease p-age-in-years p-body-mass-index p-smoker?))

rlj 2020-11-16T11:22:36.001600Z

I suppose in this case there's a good argument for avoiding the let (and this problem) altogether. But in general, I sometimes find it hard to come up with the arbitrary name.

dharrigan 2020-11-17T08:18:31.005Z

I shadow at times, because I generally try to keep my functions very small, thus I can easily trace with my eyes the code flow and I can do that mental switch when reading the code to say "ah, that name now means this (and since it's scoped to the form, it won't escape)"

dharrigan 2020-11-17T08:19:46.005200Z

So, personally, I don't have a problem with shadowing. It actually can be a mental challenge to name things (as that old truism in computer science teaches us!)

dharrigan 2020-11-17T08:20:02.005400Z

Not something I want to spend much brain cycles on

rlj 2020-11-17T10:01:45.006Z

Those are pretty much my thoughts, too. Cheers both.

2020-11-18T09:18:54.008900Z

sometimes I name things foo and foo' and foo'', etc. like a new version of the same binding

dharrigan 2020-11-18T09:22:24.009100Z

that's a nice idea, keeping the name with only a very subtle difference - quite mathematical too! I like that!

thomas 2020-11-16T12:37:55.001900Z

morning

jasonbell 2020-11-16T12:40:28.002100Z

Morning

jasonbell 2020-11-16T12:40:43.002500Z

@thomas am I still in Strictly? I’ve not kept up.

thomas 2020-11-16T12:41:17.002900Z

No, I think you failed in the dance off last week.

jasonbell 2020-11-16T13:32:08.003200Z

😞

2020-11-16T14:39:16.003400Z

Yeah, shadowing sometimes leads to gotchas but like you say good names are indeed scarce and sometimes hard to think of. Don't think there's a right answer.

2020-11-16T14:42:24.003600Z

That clojure is a "lisp-1" is one of the little things that common lispers grumble about in clojure. https://andersmurphy.com/2019/03/08/lisp-1-vs-lisp-2.html

danm 2020-11-16T16:24:45.004Z

Morning!