Fork me on GitHub
#clojure
<
2023-10-02
>
Bailey Kocin15:10:12

Is there anything I should be wary of when switching from Leiningen to "deps" on the dependency resolution and artifact builds aspect. I already transitioned to "deps" and everything seems to be running the same when I produce an uberjar artifact.... Is there a way I could compare the transitive dependencies between both builds however because I imagine "deps" and Leiningen do different things here....

Alex Miller (Clojure team)15:10:44

you jar tf the.jar | sort and then diff the output before/after

Bailey Kocin15:10:00

Amazing! Thanks

Alex Miller (Clojure team)15:10:25

I expect you may find some minor differences, particularly in META-INF

Alex Miller (Clojure team)15:10:41

for deps, there are ways to produce deps trees from both approaches. I'm not sure if there is a way to get an actual list out of lein, but from deps, use clj -X:deps list

Bailey Kocin15:10:09

You can do lein deps :tree with lein but the output is slightly different than deps so its hard to compare. I will look at the jars first manually, I did not know you could do that with the jar tool

vemv15:10:40

if you add :pedantic :warn to the Lein side, you may see areas that would benefit from some explicitness (and that may coincide with any possible deps<>lein diff)

Alex Miller (Clojure team)15:10:42

if you want to understand the gory details of deps expansion and version selection, https://clojure.org/reference/dep_expansion. Maven is essentially a top-down, breadth-first expansion, keeping the first version of a dep that it encounters, whereas as tools.deps tries to select the "newest" version that it can. In both cases, versions set at the top-level will win, so that's always a fallback to force something to happen. In practice, I find that in many cases the results are either the same or negligibly different (you get a different version of deps of deps like logging libs)

dpsutton16:10:24

each has a way to get a classpath. The classpath entries include versions. Parsing and comparing that might be the easiest

dpsutton16:10:29

/Users/dan/.m2/repository/amalloy/ring-buffer/1.3.1/ring-buffer-1.3.1.jar there’s a prefix, group/artifact/version and parsing that might be the easiest way to find the libs that are the same and the ones that are different or missing

mpenet17:10:57

Generally when porting lein deps to clj deps you end up being able to drop a lot of exclusions and have more predictable deps resolution.

mpenet17:10:13

At least it’s my experience.

mpenet17:10:57

The only tricky cases with clj is when it encounters different coordinate types (git vs maven vs local) for the same artifact. But it’s quite explicit about these

Ingy döt Net20:10:02

Today I started using tokens like #__ and #______ for these forms:

(case key
  :foo (for-thought)
  :bar (ba-rella)
  #___ (default))
and
(def lst [#__
          1
          2
          3
          #__])
for alignment and avoiding reformatting purposes. Where #____ is short for #_ ___ of course. Seems like nice trick for when you want that control. I saw @seancorfield do this in a video:
(comment
  (some thing)
  ,)
but Calva will always eat that comma on reformat. Though Calva does put the comment closing paren on its own line. Do others have similar special formatting tricks?

👍 2
gratitude-thank-you 1
💡 1
Samuel Ludwig20:10:46

i've seen

(comment
  ... 
  #_())
before too, which is what I use :^)

Ingy döt Net20:10:05

I started with #_ () then #_ 1 then #_ _ then #__ then #_______ (in lightbulb order 🙂 )

Ingy döt Net20:10:13

I've also been doing lines like:

#_#_#_#_#_
to disable the next five forms (instead of prefixing each form individually)

Ingy döt Net20:10:04

I had read about #_#_ somewhere for ignoring key/val pairs and then tried it on 3 or more and it's generic in that way.

1
bzmariano21:10:32

Hello, I am using https://github.com/kkinnear/zprint for formatting with a global .zprintrc like this: {:map {:comma? false} :width 110 :style [:how-to-ns :community :respect-nl]}

seancorfield21:10:46

That comma , was an old workaround for an issue that Calva has long-since fixed. It is not needed (and in fact is counter-productive now, as you've discovered).

Ingy döt Net21:10:44

Ah I didn't know (or forgot) you used Calva. I don't use the comma trick but the idea of using ignorable syntax forms for formatting control stuck with me.

seancorfield21:10:10

My general position is "don't fight the formatter". Let it do its thing and don't use weird hacks to "force" you're own preferences onto formatting: you'll mostly just confuse other readers of your code.

Ingy döt Net21:10:39

this is dev stuff, when the formatter won't shut up

seancorfield21:10:29

I really don't like your case hack in particular. It's misleading at a glance because it looks like you have six argument forms and no default -- so you are defeating people's common understanding of code-at-a-glance.

Ingy döt Net21:10:30

I use the proper formatting when I'm done

Ingy döt Net21:10:54

I don't like the default action aligning to the left, compared to cond 's :else

Ingy döt Net21:10:45

to me it doesn't look like 6 args at all

Ingy döt Net21:10:51

It's barely noticeable :D

❤️ 1
ander23:10:39

For comment forms I do:

(comment

  *e)

🙌 1
Ingy döt Net00:10:23

You can use it to see errors of test form evals and also shorter that #__ . Love it!

seancorfield00:10:10

Interesting idea -- I haven't seen that suggestion before! I have a hot key bound to display the last exception in Portal from anywhere (so I never need to type or eval *e).

ander00:10:50

It's been useful for me! I need to get Portal into my workflow

pez06:10:43

I’m using this for rich comments:

(comment
  
  :rcf)
And Calva’s command for adding rich comments creates them like that too. Love the idea of keeping *e in there for handy reach.

wevrem17:10:16

You could try using commas to take up space, instead of #_, for example in your case form. I sometimes use commas when my key-val pair in a map is very wide and running off the edge of the screen. It helps guide my eyeballs especially inside a gnarly destructuring.

(let [{{:acme/keys [a b c e]} :level-2} :level-1}
      ,, <some-very-wide-value>
      ...]
  ...)            

seancorfield17:10:54

@UTFAPNRPT I think the issue is that some formatting tools treat commas as actual whitespace and reformats it?

wevrem17:10:12

I see that may be a problem. Happily in Calva it has left them alone for me. Unless I hit backspace, for example, with the cursor right in front of <some-very-wide-value> then it deletes all the whitespace and brings the value up on the same line as the map, which was a surprise the first time it happened, but I came to realize it was “the right thing to to”.

Ingy döt Net17:10:34

@UTFAPNRPT the comma works for me here (and Calva doesn't eat it):

Ingy döt Net17:10:55

I like it, thanks!

Ingy döt Net17:10:30

Calva does eat this comma on reformatting:

(comment
  (stuff)
  ,)
but it's not needed anyway

Ingy döt Net17:10:17

Calva eats these commas too:

[,
 foo
 bar
 baz
 ,]
->
[foo
 bar
 baz]
so I would still use
[#__
 foo
 bar
 baz
 #__]
when I want Calva to leave my list items alone for a while.

Ingy döt Net17:10:30

I know it's not actually Calva that is responsible for the formatting, but you know what I mean...

seancorfield17:10:40

become one with the default formatting options 🙂

Samuel Ludwig18:10:38

still eagerly awaiting for clj-fmt to get associative formatting (which zprint has iirc) a la

{:one   1 
 :two   2
 :three 3}

Ingy döt Net18:10:56

@seancorfield I already said I'm not avoiding the defaults (much).

seancorfield18:10:00

I know, I'm just teasing at this point :rolling_on_the_floor_laughing:

Ingy döt Net18:10:14

@U0482NW9KL1 not sure what you mean. The auto-align of values?

seancorfield18:10:57

Calva has that as an experimental formatting BTW.

Ingy döt Net18:10:25

how do you turn it on?

pez18:10:51

Calva is responsible for the formatting, I would say, even if we use cljfmt for it. The reason some commas are eaten and some not is because comma is whitespace and, depending on your settings, the formatter will remove leading and trailing whitespace.

Samuel Ludwig18:10:50

Neovim/Conjure native-full-lifer here 🥲

Samuel Ludwig18:10:26

i love it, but itd be nice to have the attention calva does

pez18:10:49

Calva has a command for vertical align of bindings. It’s pretty buggy. I don’t recommend using it.

1
Ingy döt Net18:10:11

I've been all vim for 20+ years but am now loving vscode (and calva)

pez18:10:22

Then again, I don’t fancy bindings being formatted like that. It creates too much whitespace noice in diffs.

seancorfield18:10:32

{:a 1
 :b 2
 :long-thing 3}
=> 
{:a          1
 :b          2
 :long-thing 3}
Calva format and align as a specific action from the command palette.

1
seancorfield18:10:54

(it's not a mode you turn on, just an action you take)

1
pez18:10:11

It can also be enabled in the formatting settings. :align-associative? , I think it may be.

pez18:10:16

In fact, that’s what Calva does on that command, (-> config (assoc :align-associative? true) …) or some such.

seancorfield18:10:42

Oh? I didn't know it could be handled automatically... not sure if I'd want it on every let or hash map but it is nice that it can be asked to do it...

pez18:10:44

I recommend that setting even less. 😃

seancorfield18:10:45

Ah, yikes, yeah...

(throw (ex-info "Incompatible types found in config-merger"
                        {:a a :b b :a-type (type a) :b-type (type b)}))
=> 
        (throw (ex-info "Incompatible types found in config-merger"
                        {:a      a
                         :b      b
                         :a-type (type a)
                         :b-type (type b)}))

seancorfield18:10:04

It's pretty aggressive about it! 🙂

😂 1
pez18:10:32

Calva is using an old fork of cljfmt for this. And I have given up on even trying to keep it up-to-date with changes in cljfmt. So it has old cljfmt bugs, as well as misses new cljfmt features. And the feature itself has bugs too. With some luck the new PR for adding the feature is going to merged soon. James Reaves wanted to have a last look at it, last heard.

Ingy döt Net18:10:34

@U0482NW9KL1 fwiw the vim support in vscode is pretty solid. Otherwise I couldn't do it.

Samuel Ludwig18:10:16

i did use VSCode back in the day, as a step on my text-editor pilgrimage, it is nice, but my dearest nvim (with my custom AstroNvim conf) has so much that I don't want to leave behind ❤️

❤️ 2