Let's have a look at a code snippet that a subtle issue that needs to be taken serious.
numbers = range(1000)
sum = 0
for number in numbers:
sum += number
Did you spot it? This code is calculating the sum of a bunch
of numbers and storing this information in a variable called sum
.
The code is functional, because it is calculating a sum. But doing this,
we're overriding the generic sum
function in Python, which can cause loads
of issues in a more complex bit of code.
It's also the kind of issue can could be detected automatically by running a program that checks the Python code upfront. Ruff is one such tool. It's a modern and very likeable tool written in Rust but targeted towards Python code. It can be seen as a replacement for tools like flake8 and black, which are great tools, but are a fair bit slower because they are written in Python.
The goal of this series of videos is to get you familiar with the ruff toolbelt so that you can get some automated code quality checks on your own codebases.