Home / Blog / 6 rules to name variables correctly
6 rules to name variables correctly

6 rules to name variables correctly

  • Anna KoshevaAnna Kosheva
  • January 12, 2023

    January 12, 2023

A developer reads code more often than writes it. In addition, not your own but created by others 👆 Therefore, unsuccessful names of variables — special “repositories” in which information can be placed can significantly increase time spent. So it’s important to name them so that you and your team can understand the code at a glance, even months later.

Rule 1.

Name the variables so that there is no need for comments. And they were as straightforward as possible without context and additional code study.

Rule 2.

The variable name must include letters, numbers, an underscore, and a $ sign.

Rule 3.

Do not use transliteration. Name the variables only in English. If there are problems with the language, use a translator.

Rule 4.

Do not call variables by one letter, do not use abbreviations, and avoid abbreviations except generally accepted ones.

Rule 5.

Capitalize every word except the first. Remember that variables are case-sensitive.

Rule 6.

The variable name should briefly describe its purpose. Use those that are easy to read.

Rule 7.

Do not use JavaScript-reserved words as variable names.

  • Anna KoshevaAnna Kosheva
  • January 12, 2023

    January 12, 2023

Sign up and don't miss our awesome Mage Mastery lessons and updates!

Related Posts
How to work with SCRUM?

How to work with SCRUM?

editAnna Kosheva
edit January 23, 2023

Use Scrum for managing and completing complex projects. It is widely used in software development. Learn more here.

Magento 2 development: PRO level

Magento 2 development: PRO level

editAnna Kosheva
edit November 18, 2022

Are you middle or pro in Magento 2 development? This post is for you! Learn how to improve skills and make your store better.

Combine, filter, group: SQL scripts for obtaining samples

The SQL language is an integral tool when working with data. Magento developersuse it to store, change and processinformation. Learn more here.

If you like this blog post, you may want to watch
Intermediate
 
Max Pronko
Web Icon20 lessons
Clock Icon15 hours 00 mins
Adobe Certified Professional — Magento Commerce Developer Study Group is an 10-week (1.5 hours/week) instructor-led study group. This study group will help PHP and JavaScript developers evaluate their readiness and prepare for the Adobe Certified Professional — Magento Commerce Developer exam.
Beginner
 
Max Pronko
Web Icon13 lessons
Clock Icon1 hour 57 mins
In this free course, you will learn Magento 2 development concepts and gain knowledge of building a fully functional Magento 2 Blog module. The online course will help you develop the necessary skills to become an Adobe Commerce Developer Expert.
2023 © Made with ❤ by Max Pronko