In this article we review last week's Improve Your Python Code With BetterCodeHub code challenge.
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!!
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
Seperating tz conversion into own module, separate from Flask app:
Added some unittests:
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
Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.
"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H
"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B
"This is now my favourite first Python go-to reference." - Anthony L
"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S