Code Quality Best Practices
Explore essential code quality best practices to write efficient and readable programs. Learn how limiting line length, breaking down functions, and organizing code improves clarity and maintainability. This lesson helps you develop skills for creating clean and manageable code that is easier to understand and debug.
We'll cover the following...
Code quality best practices
As stated earlier, what we focus on here is the quality of the code, not the quality of the user experience when using our applications. When writing code, there are some things we can keep in mind to make our code better, quality-wise.
We’ll take a look at some best practices and talk about why it’s a good idea to use them.
Limiting line length
Long lines are never a good idea. Look at any newspaper and think about why the text hardly ever runs on one line across the full width of the page:
A good rule of thumb is that if the line is wider than what can fit on the screen, then it’s too wide. We should use common sense and divide the code into several lines if needed, but do so in a way that makes sense.
Take a look at the following screenshot. The code shown here is just one single statement and could have been written on a single line, but that line would have been very long and hard to read. Instead, it has been broken up in separate lines, and the line breaks occur in a natural location so that the code is easier to read:
Some programming editors will assist you in determining the maximum length of your code lines by showing a line to ...