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

Improve algorithm to check RUT number #3

Open
wants to merge 1 commit into
base: 10.0
Choose a base branch
from

Conversation

unho
Copy link

@unho unho commented Feb 11, 2019

Previous code tried to apply the algorithm as described in the Wikipedia, and therefore the code was unnecessarily complex because it did the sum from the end of the RUT number, but when coding it is easier to sum from the beginning.

Also:

  • Added docstring,
  • Added some blank lines to visually separate code blocks and make code more readable,
  • Remove unnecesary variable initialization,
  • Renamed some variable to have self-descriptive naming instead of cryptic codes,
  • Postpone variable creation until they are strictly necessary,
  • Put abort earlys at top,
  • Remove unnecessary exception checking,
  • Return directly the value of the comparison instead of using if..elif, and
  • Add constants for the factors instead of creating them on runtime every time the method is called.

All these small changes also allow to significantly reduce code length.

Previous code tried to apply the algorithm as described in the Wikipedia, and therefore the code was unnecessarily complex because it did the sum from the end of the RUT number, but when coding it is easier to sum from the beginning.

Also:

* Remove unnecesary variable initialization,
* Postpone variable creation until they are strictly necessary,
* Put abort earlys at top,
* Remove unnecessary exception checking,
* Return directly the value of the comparison instead of using if..elif, and
* Add constants for the factors instead of creating them on runtime every time the method is called.
@unho unho changed the title Simplify algorithm to check RUT number Improve algorithm to check RUT number Feb 11, 2019
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.

1 participant