frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Refactoring Clojure

https://www.orsolabs.com/post/refactoring-clojure-1/
80•luu•7h ago

Comments

gleenn•5h ago
In general, it's a dream to test and refactor Clojure IMHO. Working with mostly static top-level functions, immutability by default, and mocking when necessary with the use of "with-redefs" makes writing tests easy. Also, the immutability makes it hard to break shared copies of memory which seemed to plague my earlier tangos with large Java code bases and standard OOP practices.
sammy0910•5h ago
most people I know eschew the use of with-redefs for testing because it's hard to verify that the testing environment is configured correctly as the codebase changes (but otherwise I second the points about immutability by default, and static/pure functions!)
NightMKoder•3h ago
Agreed - concretely with-redefs forces single threaded test execution. So eg you can’t use the eftest multithreaded mode.

Explicit dynamic bindings are better if you need something like this since those are thread local.

IceDane•5h ago
It's kind of funny that this article starts by showing a completely unreadable code snippet, but not because of the code, but because of the syntax highlighting scheme. There is no version of that code, or any code for that matter, that is readable using that color scheme.
slowmovintarget•1h ago
Funny thing for me was that it looked... OK. The syntax scheme was a little garish, sure, but I could read it. Then I realized I had Dark Reader engaged so I thought I'd turn it off.

Holy cow. That is difficult.

arijun•5h ago
> Our mission is to take this code and make it readable

You failed. Between the unreadable text colors and the word wrap, the code is incomprehensible. I cut and pasted it into a plaintext notes app and it was way easier to understand

NightMKoder•4h ago
Usually the controversial decision for Clojure code highlighting is rainbow parens. This color scheme is horrific and unreadable (on mobile at least).
aeonik•4h ago
I don't like the color scheme, and in some of the snippets I don't understand the correlation, but some of them, I think the structural highlighting is very nice.
leelou2•4h ago
This article hits on something I've been wrestling with in our codebase. The absence of static typing in Clojure makes refactoring feel like walking a tightrope without a safety net sometimes. I've found that building a solid test suite before any major refactoring is absolutely critical - it's the only reliable way to ensure you haven't broken anything when reorganizing code. What's worked well for us is treating functions as the primary refactoring unit rather than trying to impose OO-style refactoring patterns. Breaking down large functions into smaller, well-named pure functions has provided the most bang for our buck. We've also found that leveraging spec for runtime validation gives us some of the safety of types without giving up Clojure's flexibility. The tooling situation has improved significantly too. Cursive's refactoring tools have been solid, and I'd be curious if others have had success with the newer REPL-integrated refactoring approaches mentioned in the article. Has anyone managed to set up effective continuous integration that catches runtime errors in untested paths?
0_gravitas•3h ago
First few comments are nothing but shallow {rem,sn}arks on the formatting of the site, by users that don't even have the excuse of being recent joiners. If this is how we lead by example then it's no wonder why the quality of content+comments on this site are (imo) on the decline.
nightfly•2h ago
Even as someone who lives with transparent terminals and poor color schemes the article is _very_ hard to read though. It's not a shallow remark when the formatting completely distracts/detracts from the rest of article.
noodletheworld•2h ago
Seems fair, but refactoring is generally tricky and:

1) replacing a func with a simpler recursive func may or may not be ideal.

2) this fills me with no joy when I read it:

> It seems easier to start from scratch as opposed to refactor it. The characterization tests above will help ensuring that the returned hash map stays the same.

Its enormously hmm… what word to use. Ambitous? Foolish? Brave?

Anyway, taking code, writing some tests for it and then rewriting the entire thing so it passes the tests you wrote only barely falls into “refactoring”.

If anyone refactored my code base by simply rewriting from scratch the parts they dont like, I would be upset.

Rewriting things is hard, and its … brave… to think you can just write a few tests and then if they all pass its all good!

That only works in very trivial examples, and really, doesnt show case the strengths of clojure at all.

roxolotl•1h ago
I’ve been writing a lot of functional lisp lately for the first time and one thing that’s struck me is how easy it is to refactor. Because a form can always be reduced to its result, you can pluck them out, move them around, and evaluate them at any level of the tree. While this is true of functional programming in general the structure of lisp makes its super easy in a way it’s not in a Haskell or just functional JavaScript.
iLemming•31m ago
> struck me is how easy it is to refactor

Yes! After a few years of using Clojure for work; Fennel for configuring anything that requires Lua; Lisp-based editor, nbb and babashka for scripting — now I just can't deal with non-lispy languages without getting mentally and emotionally exhausted. It feels so taxing to have to deal with all the syntax elements, indentation, etc. So many times my thoughts got derailed due to a missing comma in some json or slightly misindented shit in yaml.

I just don't understand how I used to happily write programs before, and I did it for over a decade. Without ever being able to "transpose these two things around", "lift this structure and move it over here", "slurp this thing inside", "raise this expression", "wrap this piece into its own block", etc. And then the actual REPL — OMG, that's a song of its own accord.

Programmers with shallow understanding and lacking experience of Lisp (or straight bias against it) are missing out so much, it really is sad.

michaelteter•1h ago
The first thing I would do would be to take some of the inner forms and turn them into functions (single responsiblity). This isn't even Clojure-specific.

Lots of little, simple functions, composed... You can still use the threading at a higher function, but instead of doing the actual work at each step in the pipeline, you call a well-named function which does what that step was doing. Yes, it may feel redundant, but it absolutely improves human comprehension because it reads like clear human instructions.

Tests become much simpler too.

The only two challenges I face with this approach is 1 - naming things, and 2 - organizing. The function names tend to become quite long, since they ideally describe what the function does.

I haven't done this lately, now that the AI tools have become pretty great; I can imagine that an AI tool would be an excellent knowledge base for these many functions, and it would probably be very successful in providing additions or modifications given the clean, clear function names and brief contents.

Barrin92•1h ago
>Yes, it may feel redundant, but it absolutely improves human comprehension because it reads like clear human instructions.

That should always be how code is written, including inside of functions, which is the real problem here. Something absent from the original code that is needed in a case like this isn't more functions, it's comments and good names.

Pulling something out into a function that is purely individual application logic without intent for reuse is not the right way to use a function, whose purpose is to be called, ideally somewhere else and not just once. As Ousterhout points out in his book, proper abstractions hide information and implementation, they aren't just scaffolding that increase the surface of an interface without doing anything.

Baby is healed with first personalized gene-editing treatment

https://www.nytimes.com/2025/05/15/health/gene-editing-personalized-rare-disorders.html
599•jbredeche•9h ago•265 comments

A leap year check in three instructions

https://hueffner.de/falk/blog/a-leap-year-check-in-three-instructions.html
194•gnabgib•5h ago•68 comments

Teal – A statically-typed dialect of Lua

https://teal-language.org/
53•generichuman•2h ago•35 comments

Cracked - method chaining/CSS-style selector web audio library

https://github.com/billorcutt/i_dropped_my_phone_the_screen_cracked
5•stephenhandley•35m ago•2 comments

Initialization in C++ is bonkers (2017)

https://blog.tartanllama.xyz/initialization-is-bonkers/
102•todsacerdoti•5h ago•73 comments

Tek – A music making program for 24-bit Unicode terminals

https://codeberg.org/unspeaker/tek
96•smartmic•7h ago•12 comments

Launch HN: Tinfoil (YC X25): Verifiable Privacy for Cloud AI

104•FrasiertheLion•11h ago•82 comments

The unreasonable effectiveness of an LLM agent loop with tool use

https://sketch.dev/blog/agent-loop
242•crawshaw•7h ago•150 comments

Ollama's new engine for multimodal models

https://ollama.com/blog/multimodal-models
9•LorenDB•1h ago•0 comments

NASA keeps ancient Voyager 1 spacecraft alive with Hail Mary thruster fix

https://www.theregister.com/2025/05/15/voyager_1_survives_with_thruster_fix/
129•nullhole•2h ago•13 comments

Rolling Highway

https://en.wikipedia.org/wiki/Rolling_highway
21•taubek•2d ago•6 comments

The current state of TLA⁺ development

https://ahelwer.ca/post/2025-05-15-tla-dev-status/
93•todsacerdoti•8h ago•22 comments

I was a Theranos whistleblower. Here's what I think Elizabeth Holmes is up to

https://www.statnews.com/2025/05/15/theranos-whistleblower-tyler-shultz-commentary-elizabeth-holmes-billy-evans-haemanthus-startup/
53•iancmceachern•1h ago•17 comments

Sitting for a long time shrinks your brain even if you exercise

https://alz-journals.onlinelibrary.wiley.com/doi/full/10.1002/alz.70157
14•codexon•2h ago•5 comments

GTK Krell Monitors

https://gkrellm.srcbox.net/
28•Deeg9rie9usi•2d ago•11 comments

A Tiny Boltzmann Machine

https://eoinmurray.info/boltzmann-machine
224•anomancer•13h ago•39 comments

Show HN: Easel – Code multiplayer games like singleplayer

https://easel.games/about
50•BSTRhino•1d ago•30 comments

Malicious compliance by booking an available meeting room

https://www.clientserver.dev/p/malicious-compliance-by-booking-an
312•jakevoytko•14h ago•290 comments

Show HN: Min.js style compression of tech docs for LLM context

https://github.com/marv1nnnnn/llm-min.txt
154•marv1nnnnn•13h ago•46 comments

Lock-Free Rust: How to Build a Rollercoaster While It's on Fire

https://yeet.cx/blog/lock-free-rust/
13•r3tr0•2d ago•3 comments

"The Mind in the Wheel" lays out a new foundation for the science of mind

https://www.experimental-history.com/p/new-paradigm-for-psychology-just
50•CharlesW•8h ago•52 comments

Improving Naval Ship Acquisition

https://www.construction-physics.com/p/fixing-naval-ship-acquisition
43•Luc•9h ago•70 comments

Fetii (YC S22) Is Hiring

https://www.ycombinator.com/companies/fetii/jobs/QDjleWs-senior-operations-manager-fetii
1•Mattiommi•10h ago

In the US, a rotating detonation rocket engine takes flight

https://arstechnica.com/space/2025/05/venus-aerospace-flies-its-rotating-detonation-rocket-engine-for-the-first-time/
74•LorenDB•15h ago•58 comments

I don't like NumPy

https://dynomight.net/numpy/
362•MinimalAction•11h ago•160 comments

Refactoring Clojure

https://www.orsolabs.com/post/refactoring-clojure-1/
80•luu•7h ago•16 comments

Dr. Dobb's Journal interviews Jef Raskin (1986)

https://computeradsfromthepast.substack.com/p/dr-dobbs-journal-interviews-jef-raskin
65•rbanffy•8h ago•50 comments

Coinbase says hackers bribed staff to steal customer data, demanding $20M ransom

https://www.cnbc.com/2025/05/15/coinbase-says-hackers-bribed-staff-to-steal-customer-data-and-are-demanding-20-million-ransom.html
306•gpi•11h ago•339 comments

Show HN: Undetectag, track stolen items with AirTag

https://undetectag.com/
86•pompidoo•11h ago•82 comments

Show HN: Real-Time Gaussian Splatting

https://github.com/axbycc/LiveSplat
125•markisus•13h ago•44 comments