Better Code Hub guides you in writing Better Code. - BCH Homepage
So you pushed your code to GitHub and deployed v1, congrats! But how maintainable is your code really? Do you have tests? Is your code modular? Are your methods short and concise? What if you could hit a button and a tool conveniently checks this for you? Free and integrated with GitHub? Enter Better Code Hub from Software Improvement Group ...
You can read a nice introduction about the tool on their blog:
Higher Grades for Better Code which defines the tool as:
This newly-built software platform enables users to check the compliancy of software systems with the 10 guidelines for Maintainability introduced in the Building Maintainable Software book.
And: Better Code Hub - An ambitious yet achievable Definition of Done for Code Quality. This is a nice read to learn about the motivation behind the platform:
This triggered us to create the Better Code Hub, an online service that puts 15 years of code quality knowledge at the disposal of all GitHub developers.
It supports 16 programming languages, can run upon each Push or PR (master and branches), and shows refactoring candidates with their impact. Last but not least: Better Code Hub provides software teams a Definition of Done, in their words:
If Better Code Hub compliance is achieved, you know you’re performing like the top teams in the industry. This is because the compliance thresholds are derived from a large industry and open-source benchmark that is calibrated yearly in our software laboratory to capture the state-of-the art in software engineering.
BCH has a nice design and a "zero set-up time": just login with your GitHub account and it shows your public repos you can analyze:
At this point you can run the Analyze (play) button and SIG's tool checks the quality of you code.
BCH will check your code against their 10 guidelines for maintainable software:
These guidelines are based on an impressive body of experience:
Compliance to guidelines is derived from the Software Improvement Group's industry benchmark which consists of over 8 billion lines of code in more than 180 different technologies. SIG analyzes around 15 million lines of code every week. - Better Code Hub Homepage
Although we are a Python blog we wanted to discuss the tool here, because as Eric Elliott's tweeted:
Frameworks and APIs change fast. Software design principles are evergreen. Learn principles that translate across language barriers.
Luckily Python (and its community) endorses a lot of good practices (
import this folks!)
And we used it for a recent Code Challenge ...
I used the tool recently for our Code Challenge 30 - The Art of Refactoring: Improve Your Code:
At first I wanted to work on an old un-Pythonic script. Problem was: it would have been easy and some scripts are better dead and buried. So I thought:
Let's do something real, something that we use and has to be mainained!
Hence I decided to use this challenge to refactor our Karmabot.
Heck, why not make it more robust now?! (Zen of Python: Now is better than never.)
It scored a meager 6 on Better Code Hub, hence it could use some work ...
First I added unittests to have a regression suite.
Dealing with an external API (Slack) made this a challenge on its own, but luckily this awesome RealPython article made it relatively easy.
Then I clicked BCH's Analysis button on the repo. Its guidance and rich UI made it a joyful experience. I refactored more than I anticipated making the solution leaner and better maintainable (although not as granular commit history here for reference).
OK that's better, now we can actually start refactoring!
Various issues here: number of branch points, 3 method (interface) params and violation of the Single responsibility principle. This example led to various refactorings even changing part of the karma module into a class.
Although not the final result, BCH made the refactoring progress very visual:
When I thought I was done BCH still pointed out I should "Couple Architecture Components Loosely". It turned out
karma.py were too entangled:
karma.py solved this.
It felt like everything fell into place, probably due to earlier refactorings. This was one of those aha moments.
And the final result:
Lastly SIG made a nice badge you can add to your Project's README:
Some code to refactor? Or starting a brand new project? Try this tool out and let us know what you think in the comments below.
You can follow / reach out to them on Twitter.
For above mentioned and other interesting articles check out their Medium page.
And above all keep learning and growing. Writing quality code is hard and takes a lot of practice (I am no expert, I am the student).
A final word of thanks. I feel fortunate to be able to learn from SIG's body of experience and knowledge and their new platform that brings their SW quality guidelines to the greater community. Great job SIG!
Keep Calm and Code in Python!
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