Fork me on GitHub
#clojure-uk
<
2019-05-22
>
dharrigan06:05:00

Morning! I've been writing a little demo to show people at work Clojure - it's a "port" of a kotlin app that does a few rest calls, a bit of transformation, consumption from kafka, into clojure

guy06:05:11

nice one!

guy06:05:23

Do you use like edn topics or something like that?

dharrigan07:05:40

@guy, edn topics? never heard of that - is that data stored in edn format on topics?

guy12:05:51

Yeah @U11EL3P9U We have avro, json and sorta ‘internal’ edn topics.

guy12:05:09

If you have clojure kafkastreams app using all the data, it seems silly to turn it into json and back agian

dharrigan12:05:55

k, thanks. Actually, it's a little demo showing the ingestion of data in JSON format (from one of our production streams) and doing an upsert via a restful api call

dharrigan12:05:05

so no squirting back unto kafka after ingestion 🙂

guy12:05:14

ahhh ok :thumbsup:

danm09:05:13

All our stuff just uses a JSON parser to turn string JSON into Clojure maps and vectors

benedek09:05:35

this reminds me some discussions around similar topics. so perhaps worth mentioning that there are edn parser libs for other langs/platforms too

benedek09:05:24

although you could possibly argue that transit is more for this kind of thing really…

dharrigan09:05:43

I asked this in #vim, but perhaps some thoughts would be beneficial here...

dharrigan09:05:52

What's the view on aligning map values, i.e., this

dharrigan09:05:07

(def my-map {:a "A value"
             :blarg :another-value
             :foo {:test "A nested map"
                   :c :d}})

dharrigan09:05:18

(def my-map {:a     "A value"
             :blarg :another-value
             :foo   {:test "A nested map"
                     :c    :d}})

dharrigan09:05:43

cursive has the later as the default, which I sorta see makes sense, esp with large edn files with lots of submaps

dharrigan09:05:00

imho makes it easier to read, but <shrug> since I'm a total n00b at this, just gaining feedback

dharrigan09:05:37

The clojure style guide, "https://github.com/bbatsov/clojure-style-guide" doesn't say one way or the other which is preferrable.

Wes Hall10:05:20

FWIW (not much) I hate the, “align all the values” style.

Wes Hall10:05:01

I just find all the white space hard on my eyes, and it’s weird to me that adding a later key changes all the spacing of earlier ones potentially.

rickmoynihan10:05:14

I personally tend to prefer the former (unaligned) unless you’re emphasising some pattern. I find aligning breaks the flow of clojure code. Other’s prefer aligning. It’s just a preference. FWIW Rich Hickey doesn’t align either; but some would say his unconventional approach to formatting java means he’s not to be trusted on such things 🙂

Wes Hall10:05:59

Haha @ that last paragraph

rickmoynihan10:05:03

I personally don’t mind his java formatting. There is a certain logic to it.

rickmoynihan10:05:17

Though I do prefer a more classical style.

Wes Hall10:05:05

Definitely can see the logic or it, I just remember the first time I looked at the Java stuff in Clojure and thinking, (with more than a little awe...), “this man gives precisely zero fucks...”.

👍 4
Wes Hall10:05:55

15 years of Java work, debating all the little style and convention issues, and Rich just comes along with a stonking rendition of, “I did it myyyyyyyy way!!!” 😂

dharrigan10:05:24

Yup, 100% agree. I remember first looking at his Java code, thinking - "Was this code autogenerated?"

bronsa10:05:52

some of it is, FWIW :)

dharrigan10:05:13

Anyhoo, thanks peeps for the feedback, I guess it all comes down to (as in much of life) as "it's up to you..."

practicalli-john10:05:07

I have all my let and {} values aligned, makes it much more readable and aesthetically pleasing to my eyes. I use the CIDER settings to vertically align and aggressively indent on my own projects.

alexlynham11:05:02

I don’t indent as it looks messy to me - and different editors will try and do different things to it ime

mccraigmccraig11:05:59

and line-endings are inconsistent across different platforms too, and there's the whole 100-year-tab-space-war thing, so i agree @alex.lynham, better to just put everything on one line

alexlynham11:05:04

tbh my default for clojure is ‘whatever paredit does for me is probably correct’ 😂

rickmoynihan11:05:40

💯 — though clojure-mode is what typically does indentation in Emacs but point still stands. clojure-mode, and originally probably lisp-mode is essentially what the style guide was based on.

alexlynham11:05:09

I assumed it was paredit bc of the structural side

rickmoynihan11:05:41

major-mode’s normally do the indentation… though minor-mode’s might do it too… not sure tbh

rickmoynihan11:05:58

but it’s usually your language mode that’s doing it

rickmoynihan11:05:38

but don’t quote me on that — it’s Emacs and might as well be the wild west 🙂

Wes Hall11:05:42

I think that this does raise the intriguing question of, “why does the way we view code have to correspond to how it’s stored?”. Why do two people, on the same team, with different preferences, have to fight it out? Why can’t I just configure my editor to give me my preference, and they, theirs?

rickmoynihan11:05:30

indeed, another old argument 🙂

rickmoynihan11:05:23

There is also a movement pushing for a gofmt approach… https://news.ycombinator.com/item?id=18620309 which makes sense; but I can’t see it happening.

dominicm12:05:41

@wesley.hall the easy answer (particularly in C) is that we encode intentions that can't be inferred into our indentation.

dominicm12:05:39

We are struggling to write a formatter that works for one case that makes people happy, let alone a customizable one for individuals.

Wes Hall14:05:02

@dominicm Indeed. I would imagine that this kind of things might be difficult in some language, but this should surely be another strength of Clojure right? If we are really drinking the, "code is just data" cool-aid. Then why not decouple code and presentation. Why can't my editor config be "CSS like"?

dominicm14:05:55

@wesley.hall common misconception, clojure is harder (depending on how you measure). Because of how macros are formatted.

Wes Hall14:05:20

You might have to unpack that for me.

rickmoynihan14:05:47

People want to format macros differently depending on the specific details of the macro

rickmoynihan14:05:01

You can put that formatting info into the macro def though

dominicm14:05:34

But then you need a running JVM, graal cannot help with this because you need an evaluator. This is another point of contention.

rickmoynihan16:05:14

Not sure you need eval for this. You don’t need to expand the macro, you just need to be able to read syntax and resolve symbols to their definitions, and when a symbol resolves to a macro parse the :style/indent off the defmacro form. You should be able to do this statically for 99% of cases… but I could be missing something.

dominicm16:05:18

Whether to be static or dynamic is pretty contentious in itself. You can cover most cases by just doing core & core libraries, but people still get upset

rickmoynihan16:05:58

Well that’s a difference between cider and cursive; there are clear trade offs with each… My point is that to use :style/indent for formatting you can do it reliably with either approach.

rickmoynihan16:05:14

so cider can do it dynamically

rickmoynihan16:05:30

and a 3rd party graal based command line tool could do it statically

rickmoynihan16:05:51

they’d just need parse-clj available or an equivalent

dominicm16:05:30

It would need to be tools reader I'd guess, like #trin

rickmoynihan16:05:09

yeah tools.reader would do it

rickmoynihan16:05:20

haven’t seen trin before

rickmoynihan16:05:59

ok so trin is expanding on what Rich did in REBL

dominicm16:05:48

Is it? I wouldn't have described it like that.

rickmoynihan16:05:58

yeah just read further… maybe not

rickmoynihan16:05:56

but could possibly support that use case but handle the case of anonymous functions and their transitive deps

rickmoynihan16:05:06

which Rich’s reflection implementation didn’t

dominicm16:05:20

But only by being so static

dominicm16:05:37

Rich could just update clojure to support that

dharrigan14:05:45

phew! I just got my head around destructuring nested maps (for binding in a let)

👍 4
dharrigan14:05:54

that took a bit of repl'ing to get right

dharrigan14:05:28

but you know what, it was fantastic - just playing around, trying out different things and having the repl report back an error, or missing names, was great!

dharrigan14:05:48

real-time programming 🙂

guy14:05:07

i find the repl to be the best

guy14:05:14

its very fun really 😄

guy14:05:42

(except for repl related profile issues ofc, thats just annoying)

practicalli-john14:05:28

Hello, my name is John. It has been two years since I wrote my last macro...

practicalli-john14:05:08

Oh, sorry. I thought this was Macro Anonymously channel 😁

😂 4
dharrigan15:05:08

All are welcome here 🙂

dharrigan15:05:11

No judgements

maleghast15:05:51

"The first rule of Macro Club is..."

guy15:05:24

“Don’t write macros unless you need to, but really someone else has probably done it already”

❤️ 8
maleghast15:05:39

"Don't write any stinking macros!"

😂 8
alexlynham15:05:22

it isn’t working!!

👀 4
mccraigmccraig15:05:40

we have 67 defmacro and 5432 defn ... sometimes there is no substitute for a macro

dominicm15:05:38

I wish I could do anonymous macros

mccraigmccraig15:05:15

how would that work @dominicm?

jasonbell15:05:24

You can @dominicm just don’t tell anyone…

dominicm15:05:24

@mccraigmccraig it probably wouldn't tbh :) everything is out of order

bronsa15:05:57

tools.macro has macrolet from common lisp

dominicm15:05:12

Ah, a macro could define how to run the macro, clever.

bronsa15:05:12

yeah, nothing preventing you from using macroexpand from within a macro

bronsa15:05:32

in fact core.async's go has to for example

rickmoynihan16:05:36

Indeed. There are lots of funky tricks you can do for more advanced macros… calling macroexpand in your macro is one neat trick 🙂, adjusting expansion orders / walking syntax are others.