Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Simplify code and speed up for loops #1631
Simplify code and speed up for loops #1631
Changes from 2 commits
79adaf6
583fc76
40c5bba
f006111
0346793
022f013
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one I'd prefer to leave as is -- the descriptive labels for the names help me understand the logic and I don't feel that two-levels of nested ifs simplify the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you feel about:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's still much slower for me to read and not faster for the computer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 on this. Just hides that it's returning a boolean value and doesn't offer a real speedup. It also makes it harder to add other future tests without encouraging people to make multiline boolean returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does it hide that? I see the second point though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 as above -- I generally prefer the expanded way unless there's a real space/mind/memory savings from returning the value of a boolean expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why? To me the short boolean expression would seem much easier to parse/understand quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's much harder for me to keep track of why we're returning what we're returning and it's really not a speed improvement in the system. In the old system we test one thing and if it's good, we return True, and then we test another thing, and if it's good, we return True. Then if we get to the end, we return False. Very easy to look at the logic. In the new way, I have to look ahead and see "is there going to be an and clause? Are we going to add the values and do something with it? Are the parentheses there for a reason or only because the line is too long?"
It just makes me read code slower, and there's no discernible speedup.