Skip to content

replace collection.size() > 0 with not collection.isEmpty()#1420

Merged
richardstartin merged 1 commit into
masterfrom
richardstartin/collection-isempty
May 1, 2020
Merged

replace collection.size() > 0 with not collection.isEmpty()#1420
richardstartin merged 1 commit into
masterfrom
richardstartin/collection-isempty

Conversation

@richardstartin
Copy link
Copy Markdown
Contributor

It would be nice to enforce this with static analysis.

@richardstartin richardstartin requested a review from a team as a code owner May 1, 2020 09:47
Copy link
Copy Markdown
Contributor

@devinsba devinsba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right that the benefit here is that size() on some collections is a linear time operation?

@richardstartin
Copy link
Copy Markdown
Contributor Author

Yes, it virtually never matters but if you don't know/control the collection implementation it's just risk averse to prefer !c.isEmpty() over c.size() > 0.

@dougqh
Copy link
Copy Markdown
Contributor

dougqh commented May 1, 2020

Nice. This has actually bitten us once or twice before -- and would definitely like to see us get in the habit of using isEmpty() rather size() > 0.

@richardstartin richardstartin merged commit db13dab into master May 1, 2020
@richardstartin richardstartin deleted the richardstartin/collection-isempty branch May 1, 2020 14:50
@github-actions github-actions Bot added this to the 0.51.0 milestone May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants