This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-07
Channels
- # announcements (5)
- # asami (17)
- # aws (11)
- # babashka (67)
- # beginners (90)
- # calva (13)
- # cider (17)
- # circleci (6)
- # clj-kondo (3)
- # clojure (53)
- # clojure-europe (12)
- # clojure-france (8)
- # clojure-germany (3)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (4)
- # clojure-spec (15)
- # clojure-uk (8)
- # clojurescript (41)
- # cursive (7)
- # data-science (6)
- # datomic (8)
- # emacs (10)
- # exercism (1)
- # figwheel-main (2)
- # fulcro (5)
- # graalvm-mobile (97)
- # graphql (1)
- # hyperfiddle (7)
- # inf-clojure (6)
- # interop (4)
- # introduce-yourself (5)
- # jobs (3)
- # kaocha (3)
- # malli (8)
- # meander (8)
- # music (3)
- # nrepl (7)
- # observability (1)
- # off-topic (45)
- # overtone (2)
- # polylith (63)
- # portal (2)
- # re-frame (26)
- # reveal (8)
- # ring (3)
- # shadow-cljs (56)
- # tools-build (5)
- # vim (11)
- # xtdb (8)
So lets say you've got 163k lines of re-frame app (spa + mobile app) developed over the last 6 years and you want to start normalising and refactoring to make it more easier to reason about and maintain.
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
ClojureScript 1405 9034 667 137420
ClojureC 7 115 16 25472
Clojure 3 20 4 225
-------------------------------------------------------------------------------
SUM: 1415 9169 687 163117
-------------------------------------------------------------------------------
I use IntelliJ/Cursive and the refactoring tools aren't great for this sort of thing. e.g. Moving things between namespaces, splitting out re-frame registrations etc. Not finding them helpful. I bet emacs is better but my fear is the learning curve doesn't make it an easy tool to pick up.
I see rewrite-clj but my gut says cutting code to refactor code is probably a temptation I should avoid.
What would you do?
I probably need to hear: roll your sleeves up and do it systematically. It won't be fun.While I'm looking at stats • 1113x reg-event • 331 reg-sub
emacs does indeed have some impressive refactoring https://github.com/clojure-emacs/clj-refactor.el/wiki
I have some good news and some bad news. The good news is that Cursive’s moving things around refactorings will get better soon, due to some work I’m doing now on ns rewriting. The bad news is that: > roll your sleeves up and do it systematically. It won’t be fun. is still going to be the correct answer.
you could use something like doom emacs or spacemacs if you want an emacs distro that helps you get things all set up for this kind of thing
I’m interested to know what you mean by splitting out registrations, what is involved there?
@U02N27RK69K nice idea thanks
@U0567Q30W that one is pretty mechanical...
I have lots of (reg-event-fx ::name (fn []...)))
I want defns for handlers
I might move the reg-event-fx to another file
So move an fn
to a defn
and replace the original with a reference to the new var?
I can almost do it neatly with many cursors but there's no way to make a nice defn name based on a fully qualified keyword
That's the idea
If I could kebabify
the qualified keyword en-mass I'd be basically happy
@U0567Q30W sepearate but a way to replace all "::" use across the codebase would make moving stuff between namespaces safer but perhaps your new developments will cover that.
All surmountable really
Yes, copying and pasting between namespaces will get better shortly, I’ll be fully-qualifying all code before copying it, and then shortening the qualified version on paste, which is what IntelliJ does for e.g. Java.
sounds perfect
I didn't think about the fact it was cljs @U0567Q30W, good call
clojure-lsp has some refactorings that may be helpful
For any sufficiently complex system there are many cross cutting concerns for everything, so any single organization is going to obscure things
So there is no promised land, and if there is no promised land, is there really a benefit to doing a code base reorg?
And what are the costs? How many man hours, rewriting, testing, for no additional features
Let's not embrace chaos just yet!
It was a bit of a throwaway statement. There are various justifications for specific refactoring in this case.
Let's save the subject for another thread.
(At me into it if you feel like exploring)
Before doing big refactoring you might want to use something like CodeScene: http://codescene.com
Interesting.
Have you used that with Clojurescript before?
Not really but we use it for Clojure backends (I'm obviously biased since I work for them :) )
I see kebabify
namespace keys as one thing, that’s just a regexp away. @U055DUUFS what exactly would you like to do?
There's been a enough random pokes on the specific challenges i'd like to improve on in this specific codebase. I'll work up a gist and share them.
Regarding kebabify. There are over 1000 event handlers registered across the codebase, say 50 files. We often used the (reg-event-fx ::x (fn [a b]...))
pattern. I want defns for each handler for testing purposes. I also plan to move registrations out of the namespace so tests can load files without having registration side effects. The event id was either ::foo
or :bar/baz
and sometimes either/with.dotted-name
. Using IntelliJ I can use the multi-cursor approach to find reg-event, copy the keyword, find the fn, make it a defn above the registration. The niggle is picking a sensible handler name. It often works to take the event-id (keyword) and use the name with a "-handler" suffix. Not always though. A dot in the name part leads to an invalid symbol. Two events with the same name part causes a clash. Handling the three forms of keyword makes the process fiddly.
http://conal.net/papers/drafts/spacetime-computation.pdf Making data layout and computational resources explicit, rather than implicit, in a functional paradigm. > In addition to eliminating scheduling and layout (or simply “spacetime layout”) errors, there is a very simple criterion for functional correctness: “spacetime erasure” yields a desired purely functional computation. The design methodology thus formally relates simple precise specifications (as spacetime-independent functional programs) to efficient, spacetime-located implementations. I know we're all big on dynamic types here, but if static typing can spare me the trouble of figuring out array sizes and other data layout questions for high-performance work I will happily embrace it in that context.
place-oriented-programming 😅
I studied geography and I can tell you right now that space and place are quite different and are used very differently in the literature broadly speaking, place is concrete and specific (e.g. a location - Los Angeles, Jakarta, etc), whereas space is abstract and non-specific (e.g. things like distance, scale, etc). I think the distinction is actually quite relevant here; the transformation described in this paper is not at all tied to implementation or hardware-specific details (place) but instead is a very general transformation from "pure" to "spatiotemporal" programs that works across systems and architectures (space).
in fact, in The Value of Values, where https://github.com/matthiasn/talk-transcripts/blob/master/Hickey_Rich/ValueOfValues.md was coined, Rich Hickey makes a very similar distinction between place and space: > What's really interesting about the definition of space is that it has always, if you go back to the oldest definitions in the oldest languages, the definition of space has always incorporated both place and time. It's never been something that applied only to one or the other of those two things. It's always connected to two and there's a certain physics aspect to that. One thing I like about that Conal Elliott paper is that it gets away a bit from the assumption of "infinite space" that's in Rich Hickey's argument, while still keeping the notion of space appropriately abstract. I think the assumption of unbounded and forever increasing computational resources (a common assumption across our profession, definitely not limited to this talk - and he does talk a bit about needing to manage garbage and reclaim some of those storage resources) is one that is ultimately quite unsustainable from an ecological point of view.
Neat, I appreciate your chiming in on the distinction between space & place
I studied geography and I can tell you right now that space and place are quite different and are used very differently in the literature broadly speaking, place is concrete and specific (e.g. a location - Los Angeles, Jakarta, etc), whereas space is abstract and non-specific (e.g. things like distance, scale, etc). I think the distinction is actually quite relevant here; the transformation described in this paper is not at all tied to implementation or hardware-specific details (place) but instead is a very general transformation from "pure" to "spatiotemporal" programs that works across systems and architectures (space).