PLAY PODCASTS
Measuring Python Code Quality, Simplicity, and Maintainability
Episode 117

Measuring Python Code Quality, Simplicity, and Maintainability

The Real Python Podcast · Real Python

July 15, 20221h 6m

Audio is streamed directly from the publisher (dts.podtrac.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.

Show Notes

<p>How maintainable is your Python code? Is it possible to hold the code for your functions in your head? When is it appropriate to use measurements in a code review? This week on the show, Reka Horvath and Ben Martineau from Sourcery are here to discuss their recent PyCon talk, &ldquo;Actionable insights vs ranking: How to use and how NOT to use code quality metrics.&rdquo;</p> <p>Reka and Ben share their thoughts on how metrics can provide insights into your Python code. We discuss four measurements of code complexity and what factors into each.</p> <p>We also talk about deciding whether to refactor or rewrite code. Ben and Reka share their experience in code review situations and the importance of shifting the conversation from subjective opinions toward objective measurements.</p> <div class="alert alert-primary" role="alert"> <p><strong>Course Spotlight:</strong> <a href="https://realpython.com/courses/writing-idiomatic-python/">Writing Idiomatic Python</a></p> <p>What are the programming idioms unique to Python? This course is a short overview for people coming from other languages and an introduction for beginners to the idiomatic practices within Python. You&rsquo;ll cover truth values, looping, DRY principles, and the Zen of Python.</p> </div> <p>Topics:</p> <ul> <li>00:00:00 &ndash; Introduction</li> <li>00:01:54 &ndash; Reka&rsquo;s tutorials on Real Python</li> <li>00:02:45 &ndash; PyCon US 2022 Talk </li> <li>00:06:01 &ndash; Code reviews and metrics</li> <li>00:09:42 &ndash; Trying to make things more objective</li> <li>00:13:24 &ndash; Sponsor: CData Software</li> <li>00:14:07 &ndash; Measuring WTFs/min and magical code</li> <li>00:16:39 &ndash; Pythonic, idiomatic, and clean code</li> <li>00:21:17 &ndash; Sourcery.ai and refactoring</li> <li>00:24:04 &ndash; Four metrics to measure</li> <li>00:24:56 &ndash; Function length</li> <li>00:30:05 &ndash; Cyclomatic complexity</li> <li>00:36:49 &ndash; Video Course Spotlight</li> <li>00:38:21 &ndash; Cognitive complexity</li> <li>00:44:38 &ndash; Working memory</li> <li>00:51:49 &ndash; Suggestions on how to use the metrics</li> <li>00:58:34 &ndash; Generating measurements</li> <li>01:01:36 &ndash; What are you excited about in the world of Python?</li> <li>01:03:30 &ndash; What do you want to learn next?</li> <li>01:05:31 &ndash; Thanks and goodbye</li> </ul> <p>Show Links:</p> <ul> <li><a href="https://sourcery.ai/">Sourcery | Automatically Improve Python Code Quality</a></li> <li><a href="https://sourcery.ai/blog/working-memory/">Can you fit all of this code in your head?</a></li> <li><a href="https://www.youtube.com/watch?v=N_hgD1eA7ks">Talk - Reka/Ben: Actionable insights vs ranking How to use and how NOT to use code quality metrics - YouTube</a></li> <li><a href="https://realpython.com/pandas-python-explore-dataset/">Using Pandas and Python to Explore Your Dataset – Real Python</a></li> <li><a href="https://refactoring.com/">Refactoring - Martin Fowler</a></li> <li><a href="https://www.osnews.com/story/19266/wtfsm/">WTFs/m – OSnews</a></li> <li><a href="https://blog.codinghorror.com/whos-your-coding-buddy/">Who&rsquo;s Your Coding Buddy?</a></li> <li><a href="https://en.wikipedia.org/wiki/Principle_of_least_astonishment">Principle of least astonishment - Wikipedia</a></li> <li><a href="https://www.youtube.com/watch?v=dqdsNoApJ80">Anthony Shaw - Wily Python: Writing simpler and more maintainable Python - PyCon 2019 - YouTube</a></li> <li><a href="https://realpython.com/python-refactoring/">Refactoring Python Applications for Simplicity – Real Python</a></li> <li><a href="https://en.wikipedia.org/wiki/Cyclomatic_complexity">Cyclomatic complexity - Wikipedia</a></li> <li><a href="https://www.sonarsource.com/docs/CognitiveComplexity.pdf">Cognitive Complexity: A new way of measuring understandability - SonarSource</a></li> <li><a href="https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two">The Magical Number Seven, Plus or Minus Two - Wikipedia</a></li> <li><a href="https://pypi.org/project/wily/">wily · PyPI</a></li> <li><a href="https://github.com/sourcery-ai/sourcery-analytics">sourcery-analytics: A command line tool and library for statically analyzing Python code quality.</a></li> <li><a href="https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code: A Handbook of Agile Software Craftsmanship - Robert C. Martin</a></li> <li><a href="https://docs.python.org/3/tutorial/errors.html">Errors and Exceptions — Python 3.10.5 documentation</a></li> <li><a href="https://www.rust-lang.org/">Rust Programming Language</a></li> <li><a href="https://benhmartineau.medium.com/">Ben Martineau – Medium</a></li> <li><a href="https://sourcery.ai/blog/">Sourcery | Blog</a></li> <li><a href="https://www.youtube.com/watch?v=rmHDhAohJlQ">The Prodigy - &lsquo;Breathe&rsquo; - YouTube</a></li> </ul> <p>Level up your Python skills with our expert-led courses:</p> <ul> <li><a href="https://realpython.com/courses/python-vs-javascript-for-python-devs/">Python vs JavaScript for Python Developers</a></li> <li><a href="https://realpython.com/courses/testing-your-code-with-pytest/">Testing Your Code With pytest</a></li> <li><a href="https://realpython.com/courses/writing-idiomatic-python/">Writing Idiomatic Python</a></li> </ul> <p><a rel="payment" href="https://realpython.com/join">Support the podcast &amp; join our community of Pythonistas</a></p>