Skip to content

potential code refactor, optimize code performance #316

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

Merged
merged 14 commits into from
Jan 22, 2021
Merged

potential code refactor, optimize code performance #316

merged 14 commits into from
Jan 22, 2021

Conversation

tusharnankani
Copy link
Contributor

References to other Issues or PRs or Relevant literature

Brief description of what is fixed or changed

This PR includes:

  • Remove unused imported modules [Anti-pattern]

  • Remove unnecessary else / elif used after return or raise

    • return statement causes the control flow to be disrupted, making the else / elif block here unnecessary. This doesn't mean you can not use it, but it is recommended to refactor this for better readability.
  • Remove unnecessary use of comprehension.

    • It is unnecessary to use a comprehension just to loop over the iterable and create a list/set/dict out of it. Python has a specialized set of tools for this task: the list/set/dict constructors, which are faster and more readable.
  • Changing the default arguments.

    • It is recommended not to use a mutable like list or dictionary as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.
  • Remove dict() and use {}

    • It is slower to call e.g. dict() than using the empty literal, because the name dict must be looked up in the global scope in case it has been rebound. Same for the other two types like list() and tuple().
  • Use tuple instead of multiple conditions, simplifying if expression.

Other comments

@czgdp1807
Copy link
Member

czgdp1807 commented Jan 19, 2021

Are you participating through any open source program? If yes then please let us know the name of the program so that appropriate label can be attached.

@codecov
Copy link

codecov bot commented Jan 19, 2021

Codecov Report

Merging #316 (cf77e6d) into master (e639bc6) will decrease coverage by 0.057%.
The diff coverage is 94.736%.

@@              Coverage Diff              @@
##            master      #316       +/-   ##
=============================================
- Coverage   98.885%   98.828%   -0.058%     
=============================================
  Files           25        25               
  Lines         3052      3072       +20     
=============================================
+ Hits          3018      3036       +18     
- Misses          34        36        +2     
Impacted Files Coverage Δ
...datastructs/miscellaneous_data_structures/queue.py 100.000% <ø> (ø)
pydatastructs/trees/binary_trees.py 97.797% <ø> (-0.003%) ⬇️
pydatastructs/utils/misc_util.py 98.765% <71.428%> (-1.235%) ⬇️
pydatastructs/graphs/adjacency_list.py 100.000% <100.000%> (ø)
pydatastructs/graphs/adjacency_matrix.py 100.000% <100.000%> (ø)
pydatastructs/graphs/algorithms.py 99.491% <100.000%> (ø)
pydatastructs/linear_data_structures/arrays.py 100.000% <100.000%> (ø)
pydatastructs/trees/heaps.py 97.948% <100.000%> (+0.021%) ⬆️
pydatastructs/trees/space_partitioning_trees.py 97.656% <100.000%> (ø)
pydatastructs/linear_data_structures/__init__.py 100.000% <0.000%> (ø)
... and 1 more

Impacted file tree graph

@czgdp1807
Copy link
Member

There are a bunch of if-return which need to be restored to if-elif groups.

@czgdp1807 czgdp1807 merged commit 592dade into codezonediitj:master Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants