bbatsov / clojure-style-guide

A community coding style guide for the Clojure programming language
https://guide.clojure.style
4.01k stars 279 forks source link

Thread on single line with single-argument functions #206

Open MicahElliott opened 4 years ago

MicahElliott commented 4 years ago

When threading a few calls single-argument calls that will fit within 80 characters, prefer a single line.

;; good
(-> x fizz :foo first frob)

;; not as good
(-> x
    fizz
    :foo
    first
    frob)

But when one of more functions takes arguments, split each call onto a separate line.

;; good
(-> x
    (fizz a b)
    :foo
    first
    (frob x y))

;; not as good
(-> x (fizz a b) :foo first (frob x y))
bbatsov commented 4 years ago

I agree with the general premise, although I guess that's a bit subjective. Still, I wouldn't mind if we mention those suggestions in the guide.

danielcompton commented 4 years ago

This seems subjective to me and hard to make a recommendation for when to use one or the other.

Often I find that I'll split a threading macro onto multiple lines if I want to really emphasis what is happening. Other times I'll leave it on a single line if it's a trivial transformation, even if there is a functional call with arguments.

bbatsov commented 3 years ago

Same here.