The Wayback Machine - https://web.archive.org/web/20200829181859/https://github.com/TheAlgorithms/Python/issues/2128
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

Dev sprint ideas: More tests, type hints and less complexity #2128

Open
itsvinayak opened this issue Jun 17, 2020 · 11 comments
Open

Dev sprint ideas: More tests, type hints and less complexity #2128

itsvinayak opened this issue Jun 17, 2020 · 11 comments

Comments

@itsvinayak
Copy link
Member

@itsvinayak itsvinayak commented Jun 17, 2020

currently, some of the programs use static type checking like this program but some of the programs did not use static typing.

it's a good practice to use static typing as it makes code more clear and readable, should we make it a standard for this repository.we can use mypy for testing code

more on static typing

thank you

Dev sprint ideas:

@cclauss
Copy link
Member

@cclauss cclauss commented Jun 17, 2020

We push all new contributions to use type hints as discussed in CONTRIBUTING.md.
All efforts to add type hints to existing algorithms would be warmly received.

We can use mypy for testing code

We do this already https://github.com/TheAlgorithms/Python/blob/master/.travis.yml#L17

@onlinejudge95
Copy link
Collaborator

@onlinejudge95 onlinejudge95 commented Jun 17, 2020

@cclauss How about a dev sprint kind of thing where we go about adding all such improvements?

@cclauss
Copy link
Member

@cclauss cclauss commented Jun 17, 2020

Cool idea! Another thing (a sprint topic?) that is bugging me is code complexity which we currently set to 25 but I would be much happier to see it at 15. We would need to ensure that the files have strong type hints and tests before modifying them to reduce their cyclomatic complexity.

@cclauss
Copy link
Member

@cclauss cclauss commented Jun 17, 2020

Another cool sprint topic would be to add doctests to Python files that have <10% test coverage. Some files like file_transfer/send_file.py and the web programming files are difficult to write tests for but others should be fair game.

@cclauss cclauss changed the title Static typing standard for repository Dev sprint ideas: More tests, type hints and less cyclomatic complexity Jun 17, 2020
@cclauss cclauss changed the title Dev sprint ideas: More tests, type hints and less cyclomatic complexity Dev sprint ideas: More tests, type hints and less code complexity Jun 17, 2020
@cclauss cclauss changed the title Dev sprint ideas: More tests, type hints and less code complexity Dev sprint ideas: More tests, type hints and less complexity Jun 17, 2020
@cclauss
Copy link
Member

@cclauss cclauss commented Jun 20, 2020

Should we have a short sprint or a long one? One idea would be 24 hour sprint — given that tomorrow is summer solstice (longest day of the year) — the sprint could start at midnight tonight (in whatever timezone the contributer is in) and last for 24 hours. #2128 could be our tracking issue for keeping track of tasks and accomplishments. Thoughts on this Summer Solstice Special Sprint idea.

@onlinejudge95
Copy link
Collaborator

@onlinejudge95 onlinejudge95 commented Jun 20, 2020

Seems awesome, we can gain some attention by Summer Solstice Special Sprint, I am up on gitter if you want to discuss

cclauss added a commit that referenced this issue Jun 21, 2020
Work In Progress Draft: Do not merge if test are not passing!!

Related to #2128, find all files that contain algorithms with > 15% McCabe complexity.
cclauss added a commit that referenced this issue Jun 21, 2020
As discussed in #2128
@cclauss cclauss mentioned this issue Jun 21, 2020
0 of 14 tasks complete
cclauss added a commit that referenced this issue Jun 21, 2020
As discussed in #2128
@cclauss cclauss removed the question label Jun 21, 2020
@mateuszz0000
Copy link
Member

@mateuszz0000 mateuszz0000 commented Jun 22, 2020

Another cool sprint topic would be to add doctests to Python files that have <10% test coverage. Some files like file_transfer/send_file.py and the web programming files are difficult to write tests for but others should be fair game.

Difficult but not impossible. We can create issue with some labels. Perhaps we find someone who will write tests or even code (for example simple server for response) for testing it 😃

cclauss added a commit that referenced this issue Jun 22, 2020
* Euler problem 551 sol 1: Reduce McCabe code complexity

As discussed in #2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
cclauss added a commit that referenced this issue Jun 22, 2020
* hamming_code.py: Reduce McCabe code complexity

As discussed in #2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
peRFectBeliever added a commit to peRFectBeliever/Python that referenced this issue Jun 30, 2020
…#2141)

* Euler problem 551 sol 1: Reduce McCabe code complexity

As discussed in TheAlgorithms#2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
peRFectBeliever added a commit to peRFectBeliever/Python that referenced this issue Jun 30, 2020
* hamming_code.py: Reduce McCabe code complexity

As discussed in TheAlgorithms#2128

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
@spamegg1
Copy link
Contributor

@spamegg1 spamegg1 commented Jul 27, 2020

I have an idea. How about making the code more idiomatic and Pythonic?

For example, currently I see a lot of code of the form:

for i in range(len(some_iterable)):
    ...
    do something with i or some_iterable[i]

It is better to do:

for index, item in enumerate(some_iterable):
    ...
    do something with item or index

or if it is a dictionary:

for key, value in some_iterable.items():
    do something with key or value

This is just one example. There are also many pieces of code where comprehension can replace for-loops.

There are many other ways to write more Pythonic code. Here are some excellent videos from one of the experts of the subject:
Transforming Code into Beautiful, Idiomatic Python
Beyond PEP8 Best practices
And some excellent articles:
Code like a Pythonista: Idiomatic Python
Idiomatic Python. Coding the smart way

I understand this would be a huge undertaking, but it's just an idea that pays off greatly in the long run. We can all become better Python coders!

@cclauss
Copy link
Member

@cclauss cclauss commented Jul 27, 2020

I understand this would be a huge undertaking

Incrementalism wins. Please don't try to do this across many files at once. Instead, please find a file that needs improvement and submit a pull request to improve just that one file. Please create other similar PRs for other individual files. We can progress file-by-file in this manner.

@spamegg1
Copy link
Contributor

@spamegg1 spamegg1 commented Jul 27, 2020

@cclauss Got it.

cclauss pushed a commit that referenced this issue Jul 27, 2020
)

* added type hints and doctests to arithmetic_analysis/bisection.py

continuing in line with #2128

* modified arithmetic_analysis/bisection.py

Put back print statement at the end, replaced algorithm's print statement with an exception.

* modified arithmetic_analysis/bisection.py

Removed unnecessary type import "Optional"

* modified arithmetic_analysis/bisection.py

Replaced generic Exception with ValueError.

* modified arithmetic_analysis/bisection.py

fixed doctests
cclauss pushed a commit that referenced this issue Aug 1, 2020
…2242)

continuing #2128
cclauss added a commit that referenced this issue Aug 1, 2020
…#2259)

* added type hints and doctests to arithmetic_analysis/newton_method.py

Continuing #2128
Also changed some variable names, made them more descriptive.

* Added type hints and doctests to arithmetic_analysis/newton_method.py

added a type alias for Callable[[float], float] and cleaned up the exception handling

* added type hints and doctests to arithmetic_analysis/newton_method.py

improved exception handling

* Update newton_method.py

Co-authored-by: Christian Clauss <[email protected]>
@kanthuc kanthuc mentioned this issue Aug 18, 2020
4 of 14 tasks complete
@Feliren88
Copy link

@Feliren88 Feliren88 commented Aug 29, 2020

Hey, keen to contribute. I am first timer in open source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.