Skip to content
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

Code review v1 #2

Closed
wants to merge 31 commits into from
Closed

Code review v1 #2

wants to merge 31 commits into from

Conversation

ashald
Copy link

@ashald ashald commented Mar 14, 2014

OK, so as promised I'm sending a PR with refactoring that I've done while I was reading 'Paxos Made Moderately Complex' and learning the Paxos implementation. This refactoring can be considered as a code review.

The main changes is:

  • PEP8 fixes (though not all issues fixed)
  • code style consistency (same things should be done with same code)
  • code simplifications (removed some redundant constructions)
  • comments and TODO
  • distinguishing between public and non-public class members (all class members that weren't used from outside of a class I've prefixed with the underscore character that's so it is easier to understand which part of code is a 'public API' and which part of code is used only internally by other class methods)

As you can see, there is a lot of commits as I tried to make a lot of small changes so it will be easier to grasp the essence of the changes.

Additionally, there are few issues that should be considered though I haven't left any comments in code regarding them:

  • broken code should be removed to reduce overall amount of code - I understand that this code will not be used, but I have spent some time to understand the purpose of this code and why it is broken;
  • there is a common pattern to delay a function execution using timer; in such cases there are parts of code that introduce new class fields only for purpose of passing some data into delayed function - it would be great to consider using functools.partial instead as it will reduce amount of class fields and code will become easier to understand.
  • such things as Ballot(-1, 0, unique_id) and Ballot(-1, -1, -1) seems to be a magic - it is not clear what meaning have ballots with such fields - we should use something like a factory method with sensible name to construct such objects;
  • there are a lot of string literals with Paxos commands - 'PROPOSE', 'PROMISE', 'ACCEPT' etc - they should be moved to constants;

ashald and others added 30 commits March 10, 2014 02:31
Since list is a class we should use a super notation to use base methods in descendants. Also set_len may be considered as an internal method so add an underscore suffix to stress the fact that it shouldn't be considered as a public method.
…ode. Appropriate builtins should be used instead.
…ginal implementation was extremely unefficient.

Since peers stored as a field used only by Bootstrap added underscore suffix to field name to stress the fact that it is an internal field (not designed to be used from outside).
Short names and abbreviations aren't good even if they're widely used in standard description.
…een 'public' and 'non-public' members. Also changed some field names to include some semantic meaning.
…een 'public' and 'non-public' members. Also changed some field names to include some semantic meaning.

Added some TODOs.
* Added issues list
* Removed defaultlist usages (replaced with dict)
* Added TODOs
…tinguish between 'public' and 'non-public' members.
@djmitche
Copy link
Owner

Are you using a non-default pep8 configuration? My run of pep8 is actually reverting some changes you have made..

@djmitche
Copy link
Owner

Thanks! This was really helpful, and I've cherry-picked most of it. I didn't merge the underscore-adding diffs. The rationale is that the component classes aren't user-visible anyway, so there's no benefit to making a public/private distinction clear from introspection. I'll go into more depth on this in the text.

@djmitche djmitche closed this Mar 24, 2014
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.

2 participants