Fork me on GitHub
#rewrite-clj
<
2021-11-16
>
vemv19:11:52

from time to time I dream of a declarative refactoring engine, e.g. for every second argument given to foo , wrap it in a hashmap with key :bar. is it an idea you've entertained much? I'd imagine that is much much easier said than done 😇

lread20:11:09

Hi @vemv, no, that has not come to my mind. But there are more things in heaven and earth, vemv, than are dreamt of my wee brain! So you’d have some declarative recipe that turns:

(foo 1 2 3 4 5 6)
That would produce this?:
(for 1 {:bar 2} 3 {:bar 4} 5 {:bar 6})
Without thinking about it too much, I’d probably lean toward simply coding up something in Clojure to do the transform instead of creating some sort of DSL.

borkdude20:11:39

I would prefer coding it over a DSL myself.

borkdude21:11:19

Note that you can use other tools (like clj-kondo) to detect the positions of all the calls of foo, and then use fairly thin rewrite-clj code to transform those calls

borkdude21:11:25

The problem with a DSL is usually that it covers 80% of what you want, but then you leave it for coding anyway

vemv21:11:04

> I would prefer coding it over a DSL myself. I have mixed feelings about it. Probably a fully generalized DSL would be overly dense, but I sense that telling people to code rewrite-clj script for any possible refactoring idea would not make people very enthusiatic. Maybe the middle ground would be implementing different 'intents' that a user may want. 1 intent == 1 defn, defns might compose There's more to writing a rewrite-clj 'script' anyway i.e. traversing a codebase, filtering out false positives, etc. So I sense there's a place for a 'framework'

borkdude21:11:53

A lot of what is in clojure-lsp may already worth getting out into a library

borkdude21:11:08

and libraries I would much prefer over a framework, but this is often just a matter of framing :)