In this article we review last week’s Improve Your Python Code With BetterCodeHub code challenge.
Submissions
-
hobojoe1848 submitted his Generic Emailer Script:
This is a simple script I wrote to automate sending emails from my Gmail account. It’s generic such that I use it in various different programs. When I had BCH analyse the repo I received a score of 7, meaning it failed 3 points. The most obvious to me was the “Write Short Units of Code” test:
The original script that resulted in this score is here
Tackling this issue had me refactor the entire script after which, BCH gave me a pass and my score jumped to 8:
What a great tool! I’m a big fan of BCH after this!!
-
bbelderbos ran BCH on his small codetips Django REST Framework submission of last week: wow I was amazed to see it got a 9 right off the bat. DRF / Django lets you write quality code!
I did have to ignore the settings file adding a
.bettercodehub.yml
file to get to a 10. I also opened another issue to add tests (as the project is < 200 LOC BCH did not complain yet):I also refactored Julian’s timezone-list project improving the already nice score of 8 to a 10
-
Before:
-
Seperating tz conversion into own module, separate from Flask app:
-
Added some unittests:
-
Final score:
I also like BCH: it makes you think about your code and improve it. The tool has a nice design and performs well. I also like the GitHub workflow we learned during this challenge.
-
-
If you did some work for this challenge, PR it or message us with the details and we’ll include it here.
As there is no deadline to these challenges, we will update here when we get more cool submissions for this challenge …
Just follow our instructions and start coding!
Stay tuned for our next challenge …
Keep Calm and Code in Python!
— Bob and Julian