-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Rewrite joinWithSeparator's zero count separator if/else statement with an early-return if check #1346
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
Conversation
I find the double-negative here very hard to read: guard separatorSize != 0 else |
@gribozavr Sorry about that, I changed it to: guard separatorSize > 0 else |
It still forces a negation onto the condition. I don't see a reason to use |
There is an example of this in Where there is a similar use of a guard with no binding variable guard maxItemCounter > 0 else { return } |
I'm not a fan of that line either, FWIW, but that use is more readable, since it immediately returns. In the case of this PR, we are doing non-trivial work in the |
@gribozavr I see your point, my original intention was to simplify the the downstream code and take it out of an if/else. By doing that the code handling the more common case of having a non-empty string separator is less nested. Most of the time if someone wants to join an array of strings with no separator I would imagine that they would reach for |
If you want to add an early return and de-indent the function, that's good, but we can also use |
@gribozavr Yes the goal was to de-indent the function a bit and replace the if-else with an early return be it guard or if but now it makes more sense to use an if instead. I made the change and squashed the commits into one, how does it look now? Thanks for all the feedback! |
@swift-ci Please smoke test |
LGTM now, thank you! |
@gribozavr The Smoke test failure seems unrelated, what do you think? |
Rewrite joinWithSeparator's zero count separator if/else statement with an early-return if check
Since the majority of the time this function is called, it is called with the intention of inserting a separator
the case of the separator not existing is less common, therefore it might make intent clearer if the if/else check in this code was rewritten with a guard statement.