-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add note about preferring (if-not (= ...))
over (if (not= ...))
and (when-not (= ...))
over (when (not= ...))
#240
Comments
(if-not (= ...))
over (if (not= ...))
and (when-not (= ...))
over (when (not= ...))
(if-not (= ...))
over (if (not= ...))
and (when-not (= ...))
over (when (not= ...))
I don't think I've ever heard anyone advocate for this so I wouldn't say it was "widely-agreed" . Looking at our 140k lines of Clojure, I see just 4 occurrences of I think there's an intention preference here around I'm against adding it to the style guide but I'm not exactly in favor of it either. |
I agree with @seancorfield here, I wouldn't say I've seen strong consensus either way in the community. I can certainly see an argument for picking one approach in a company's internal style rules, but I'd be more hesitant about adding it to this style guide. |
Perhaps the suggestion should be simply to be consistent in the usage of such macros. |
FWIW, I don't really agree with the existing Given the presence already of the guideline to use In other words, I don't feel strongly one way or the other -- it would just be another part of the style guide that I'd choose to ignore. |
Well, those macros are definitely not something particularly important, so no argument from me. The value they add is on the side of less typing, not clearer code. :-) Might be good to use softer language for less important guidelines (such as https://guide.clojure.style/#when-not) - e.g. "Prefer" instead of "Use" or something along those lines. |
On a more meta topic - I think that (if-not something
foo
bar)
;; same as above, but without the redundant negation
(if something
bar
foo) That has nothing to do with Clojure, though. And I really think that |
I think Example: (if-not something
foo
(let [...]
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
bar)) as opposed to (if something
(let [...]
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
line-of-code
bar)
foo) the difference is with |
Coming back to this nearly a year later: it seems like there's no further input and no clear consensus on the suggested guidelines (although I'm reading "leaning no" overall), so I propose we close this. |
I was surprised this wasn't already in the style guide. This is a widely-agreed-upon idiom, right? Or am I just imagining things.
The text was updated successfully, but these errors were encountered: