kibit icon indicating copy to clipboard operation
kibit copied to clipboard

Single-branch if shouldn't be replaced by when.

Open technomancy opened this issue 13 years ago • 7 comments
trafficstars

The readme says that if it finds the code (if (some test) (some action) nil) it will suggest replacing it with while. I think it means when, but this isn't right; single-branched if forms are totally acceptable if the focus is on the return value. Since when has an implicit do form, it is a way of signaling to readers that side-effects are involved, while if forms are all about what value is returned. Instead consider adding a rule for replacing (if cond (do some action)) with when.

technomancy avatar Mar 04 '12 22:03 technomancy

Maybe what we really need is an easy way to configure which substitutions different users prefer?

CampingScorpion avatar Mar 04 '12 23:03 CampingScorpion

The battle continues. ;-) +1 for @AlexBaranosky's suggestion.

cemerick avatar Sep 28 '12 02:09 cemerick

Is this rule causing problems? Are you getting pull requests from users who have run kibit on your project and you don't agree with the changes (I've seen this happen)? If that's the case I'd rather just remove the rule for now until I find time to revisit this project.

jonase avatar Sep 28 '12 03:09 jonase

My apologies; I saw this issue on my way to creating #52, so perhaps the +1 wasn't especially valuable.

cemerick avatar Sep 28 '12 03:09 cemerick

@jonase yeah, I would like to use Kibit on Leiningen, but the amount of noise generated from this bug makes it annoying to try it out.

technomancy avatar Nov 20 '12 18:11 technomancy

I strongly disagree that this is a 'bug' of any sort. I personally prefer when for single branch ifs and would be disappointed if this got removed entirely.

Raynes avatar Nov 26 '12 07:11 Raynes

I'm inclined to agree with @technomancy on this. I propose removing single-branch if -> when rules, but making them available through add-on custom rules #66. Thoughts?

danielcompton avatar Nov 10 '14 12:11 danielcompton