π Hi there!
As a software engineer and educator, I spend a lot of time watching beginners write code.
And one thing always stands out: how slow it can be.
β
Not because of logic or bugs, but because of typing & formatting!
So today I suggest we talk about formatters.
β
Before we start, can you answer this tiny poll?
β
You already use a formatter when you code: |
|
|
|
If you're not using one yet, itβs an easy win that will instantly boost your productivity.
And if you already are, read on: there's some exciting news youβll want to know.
β
The problem
Without a formatter, two things usually happen:
First code is often hard to read. Take this R code snippet: it works, but itβs a headache to read:
Indentation is bad, spacings don't make sense, case is terrible and lines are too long.
β
People usually realise this which leads to the second problem: wasting time manually cleaning it up.
Fiddling with spaces, adding line breaks, fixing tabs...
β
You eventually get something cleaner, but at the cost of precious minutes. And probably not with a perfect result!
β
The solution: formatters
No matter if you code in R, Python, or JavaScript, you should absolutely be using a formatter.
A formatter is a little tool that handles the layout of your code: line breaks, indentation, spacing. It takes a set of standard styling rules and apply them automatically on your file.
It doesnβt change what your code does, just how it looks.
β
Hit a keyboard shortcut or click a button and boom: clean, readable code in an instant. π₯
β
Format on save
The best way to use a formatter is to set it to run every time you hit ctrl+s to save your file. We call this feature "format on save".
In R, the styler
package has long been the go-to formatter, following the tidyverse style guide.
It works well, and I explain how to use it in my Productive R Workflow course.
β
But styler is a bit slow and the Format On Save feature was not well supported.
Thereβs a new tool that has just been released that fix those issues. It's called Air.
Itβs blazingly fast. Formatting the entire dplyr codebase takes just 0.3 seconds! π³
β
βNote: you know how much I love Quarto. Air does not work with Quarto documents in R Studio. But it does work if you use Positron or VS code.
β
Javascript and Python
The same principle applies to Python and JavaScript too!
β
With Javascript, Prettier is usually the go-to formatter.
β
In Python, Black was one of the standard for a long time, but Ruff is definitely the way to go now, as it is much faster!
β
β
Conclusion
Using the right tools is one of the best investments you can make in your developer journey.
β
The seconds you waste on formatting manually every day add up quickly. πMinutes per day, days per year.
β
βDonβt let that time go to waste.π¨
Make the switch. There is no coming back!
Cheers,
β
Yan
PS: I'm updating my Productive R Workflow project to replace styler
with Air
in the coming days! If you like using R properly, take a look! It gives heaps of tips like this one!
β
βPPS: The students of Matplotlib Journey keep doing amazing work π. Would you know how to do that with matplotlib? (code here)
π By the way, here is how I can help!
β
- Master R: Join my productive R workflow online course, already helping hundreds to excel in R, Quarto, and GitHub.
- Team Training: Hire me to train your team on Data Visualization and Programming.
- Engaging Talks: Book me for short, impactful talks on Data Visualization and Programming.
β
Check yan-holtz.com or hit reply any time! I love hearing from you.
|
β
β
β
β
β
|
β