r/Clojure • • Jun 06 '20

[BLOGPOST] Idiomatic Clojure: Code Smells

https://bsless.github.io/code-smells/
85 Upvotes

27 comments sorted by

View all comments

2

u/fiddlerwoaroof Jun 06 '20

I tend to think

(doseq [x xs] (doseq [y ys] ...))

Is preferable to

(doseq [x xs y ys] ...)

Because I don't have to wonder whether doseq produces the cartesian join of xs and ys or processes the collections pair-wise.

1

u/onetom Jun 07 '20

It took awhile for me to remember it too, but if you have help and definition lookup available in your editor, then it's not a big hindrance...

4

u/fiddlerwoaroof Jun 07 '20

When I’m reading/reviewing code, I don’t want to have to think carefully about ambiguous constructs: I’d rather encourage a style that avoids ambiguity like this as much as possible.

3

u/bsless Jun 07 '20 edited Jun 07 '20

I've had the displeasure of seeing a 4-deep doseq with two let bindings and a when clause.

It gave me great appreciation for the rich syntax offered by for and doseq.

Also unmentioned, when using nested for, the programmer is forced to use concat, when what they wanted was just a Cartesian product.

2

u/fiddlerwoaroof Jun 07 '20

Yeah, I tend to the mindset of "just use transducers". I never use for/doseq in my own code, because the compositionality of transducers make them a lot nicer.

1

u/bsless Jun 07 '20

Agreed. Still working on familiarizing my coworkers with transducers. I have a series on those in the works.