Conventions over readability?

I previously wrote about why you shouldn't use variable names like $x and $y in your code and why you should use more descriptive names.

But what if there is an existing convention?

For example, I use Lua to configure Neovim and noticed that it's common to use shortened variable names, such as buffer instead of buffer_number or bufferNumber.

It's also common to use the variable M to declare a module. For example:

local M = {}
M.find_files = function()
  // ...
end

return M

Whilst Module would be a more descriptive name, would deviating from the convention be more confusing for anyone reading the code?

Do the benefits of following a convention outweigh the benefits of using more descriptive variable and function names?

Which would be easier for newcomers to your project or team to understand and allow them to be productive sooner?

- Oliver

P.S. Need help or want another pair of eyes on your code? Book a 1-on-1 consulting call or an online pair programming session with a 100% money-back guarantee.,

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.