⚑️ 0.3 seconds to make your code clean!


πŸ‘‹ 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?
​

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)

Yan Holtz

​Find me on X, LinkedIn, or check my Homepage​

​

πŸ‘‹ 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.

​

​

​

​

​

​

https://preview.convertkit-mail2.com/unsubscribe​
​Unsubscribe Β· Preferences​

background

Subscribe to Dataviz Universe