Uh oh!
There was an error while loading. Please reload this page.
Prefer is_empty to len() - #23682
Conversation
alexcrichton
commented
Mar 25, 2015
Hm I think I may prefer to more officially establish a convention in this regard before migrating the codebase. Along those lines I'm curious if others have thoughts on this? I'm personally pretty ambivalent, I tend to reach for |
Diggsey
commented
Mar 25, 2015
"is_empty()" is always going to run in constant time, whereas "len()" may take linear time for some containers. |
Gankra
commented
Mar 25, 2015
vecmap and bitvset still take linear time to answer is_empty if the answer is "true". If it's false they may do better depending on value locations. |
tamird
commented
Mar 26, 2015
@Diggsey good call. @alexcrichton wdyt? |
alexcrichton
commented
Mar 26, 2015
I feel like the most commonly used collections for the compiler, Overall I'd still prefer a broader consensus for changes like this. Ideally this would be a rustc-specific lint as well, but that seems over the top for something so minor. |
bors
commented
Mar 27, 2015
☔ The latest upstream changes (presumably #23359) made this pull request unmergeable. Please resolve the merge conflicts. |
bors
commented
Mar 28, 2015
☔ The latest upstream changes (presumably #23796) made this pull request unmergeable. Please resolve the merge conflicts. |
7ee6aac to
1d79eeaComparebors
commented
Apr 1, 2015
☔ The latest upstream changes (presumably #23936) made this pull request unmergeable. Please resolve the merge conflicts. |
gereeter
commented
Apr 4, 2015
I'm definitely inclined to prefer |
bors
commented
Apr 7, 2015
☔ The latest upstream changes (presumably #23857) made this pull request unmergeable. Please resolve the merge conflicts. |
tamird
commented
Apr 7, 2015
@alexcrichton I think a lint is the way to go here, and probably not a rustc-specific one. I lack the necessary rustc-fu to make this happen though, could you mark this This lint should probably suggest
WDYT? |
bors
commented
Apr 8, 2015
☔ The latest upstream changes (presumably #23998) made this pull request unmergeable. Please resolve the merge conflicts. |
bors
commented
Apr 10, 2015
☔ The latest upstream changes (presumably #24177) made this pull request unmergeable. Please resolve the merge conflicts. |
bors
commented
Apr 15, 2015
☔ The latest upstream changes (presumably #24433) made this pull request unmergeable. Please resolve the merge conflicts. |
`s/(?<!\{ self)(?<=\.)len\(\) == 0/is_empty()/g``s/([^\(\s]+\.)len\(\) [(?:!=)>] 0/!$1is_empty()/g`
alexcrichton
commented
Apr 15, 2015
Ok I find the comments here pretty convincing, so I think this is fine to go in for now. We'll probably want to discuss a little more if we want a lint for something like this, but it seems beneficial regardless for rustc itself to be consistent. Thanks for being patient and doing so many rebases @tamird! |
bors
commented
Apr 16, 2015
bors
commented
Apr 16, 2015
lambda-fairy
commented
Apr 16, 2015
@tamird That would make a great addition to https://github.com/Manishearth/rust-clippy EDIT: Filed as Manishearth/rust-clippy#32 |
nikomatsakis
commented
Apr 16, 2015
+1 to |
r? @alexcrichton