clojure-style-guide
clojure-style-guide copied to clipboard
Use empty? to determine whether a seq is empty
empty?
is simple, direct, and effective. The use of seq
as a drop-in replacement for (complement empty?)
is not style worth propagating, because it doesn't encourage straight-forward code readability.
I'm pretty sure "Joy of Clojure" had a section on the topic and the advice was the same. At least in loops it does make sense to me.
I'm not sure if that comment is agreeing or disagreeing with me, but assuming it is disagreeing, I would ask what empty?
is for if not this use?
@AlexBaranosky I hear you. This is a matter of preference, really. I personally use empty?
or seq
depending on what makes my boolean logic simpler. For example, I would always prefer (if (seq x) ...)
to (if (not (empty? x)) ...)
. Do you prefer using empty?
unconditionally?
I prefer using empty?
but Rich encourages using seq
as a predicate. There isn't widespread agreement on the topic.