Skip to content

Conversation

@Liwink
Copy link

@Liwink Liwink commented Dec 14, 2016

  • using enumerate to replace while and index
  • better indentation
@coveralls
Copy link

coveralls commented Dec 14, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling cc2c3c3 on Liwink:master into 3a7074c on joowani:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling cc2c3c3 on Liwink:master into 3a7074c on joowani:master.

Copy link
Owner

@joowani joowani left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I appreciate your interest in and contribution to the binarytree project :)

I've reviewed the changes and left a few comments.

_add_right(parent_node, child_node)
nodes[index] = child_node
index += 1
for index, value in enumerate(values[1:], 1):
Copy link
Owner

Choose a reason for hiding this comment

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

A slicing operation like values[1:] creates a new list, and is costly when the number of elements in the list is large. While your suggested change does make the code cleaner, I don't think it justifies sacrificing performance albeit small.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, great advice! And I made a change.

index += 1
for index, value in enumerate(values[1:], 1):
if value == _null:
continue
Copy link
Owner

@joowani joowani Dec 14, 2016

Choose a reason for hiding this comment

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

I think using the continue here is fine 👍

@coveralls
Copy link

coveralls commented Dec 14, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 16c78da on Liwink:master into 3a7074c on joowani:master.

Copy link
Owner

@joowani joowani left a comment

Choose a reason for hiding this comment

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

Left you another comment. Also I created a dev branch for future merges and development so please redirect your PR there. Thanks!

nodes[index] = child_node
index += 1
for index, value in enumerate(values):
if value == _null or index == 0:
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm this doesn't seem very elegant as we are adding an unnecessary check every iteration. I don't see a compelling reason to use enumerate here. We can keep the continue as I've said before to reduce indentation!

@joowani
Copy link
Owner

joowani commented Jan 12, 2017

Hi @Liwink

I will be closing this PR as there does not seem to be changes that add compelling value. Thank you for your contribution regardless, and feel free to make more pull requests in the future!

@joowani joowani closed this Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants