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

13

u/Borkdude Jun 06 '20

I would not recommend using merge instead of assoc in spots where performance matters. Please watch this talk: https://www.youtube.com/watch?v=3SSHjKT3ZmA&list=PLetHPRQvX4a-c3KDRTxxwGRmEMutL8Apf&index=16&t=0s

2

u/bsless Jun 06 '20

Completely agree and I'm a big fan of that talk.

Perhaps I should have written it in bold letters:

Just one word of warning, using merge and select-keys on a hot code path might not be desirable due to performance concerns.

Do you think I should make it clearer to the reader?

12

u/Borkdude Jun 06 '20

Maybe you could back up your recommendations with tradeoffs and explain why you favour one over another, instead of just choosing one approach and advising against the other without a clear explanation of the implications.

2

u/setzer22 Jun 07 '20

I second this. We must make programming less dogmatic. Don't tell me what I shouldn't do: Teach me and let me choose with the tradeoffs in hand.

Another clear example is the seq vs empty? case. If the seq idiom is always preferred, why use empty? at all? Moreover, why not (defn empty? [x] (not (seq x)). This is not addressed at all (not even by the docstring!)

But it was a really good post nontheless! I learnt a few tricks myself that I didn't know about.