Types add context

In yesterday's email, I wrote about why readable variable names are important and why I use descriptive variable names in my code.

Given this pseudo-code:

function hande(req, res) {
}

With the short variable names, whilst you can guess, it's unclear what the variable names are.

However, in this code, we have the same variable names, but we also have additional type information:

function handle(Request req, Response res): void {
}

Even with the same variable names, I know what their types are and what the function returns, I have better completions and diagnostics in my editor and better static analysis of my code, making it easier to identify and fix potential bugs.

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.