/ simpler code

4 Practical variable naming rules

Many developers treat variables as a place to simply dump a value, without spending much thought on picking a name. This is unfortunate, as proper naming of your variables can greatly increase the readability and maintainability of your code. A name should tell you why a variable exists, what it does and how it is used. Here are 4 practical rules for picking variable names.

Don't use ABAP style names in JavaScript
An easy way to recognize JavaScript has been written by a former ABAPer is when you see ABAP style variable names:

lv_myvariable - Don't do this

This is not a convention in JavaScript, and does not adhere to the SAP guidelines. Every UI5 developer should be familiar with Hungarian Notation, meaning variable names are prescribed by their type. Although many JavaScript developers will fiercely debate against using Hungarian Notation - I'm not the biggest fan myself - it is the SAP standard. As they say, "When in Rome, do as the Romans do".


Avoid meaningless abbreviations
Do not worry about using more horizontal space, descriptive variable names are far more important than saving a few keystrokes when typing a variable name. Of course there are cases when abbreviations are perfectly fine, but in general it is better to be as descriptive as you can.

iNErr - Meaningless abbreviation
iNumErrors - 'num' is a common abbreviation

sCstmrNm - Don't remove letters to shorten the name
sCustomerName - No abbreviation necessary

So when is a variable name too long? When there is a shorter name that will allow for better code readability.

sServiceUniformResourceLocator - Dont spell out URL
sServiceUrl - Widely used abbreviations are fine

Avoid noise
Use concise terms, that accurately describe the meaning of your variables. vague terms like 'data' or 'info' may signal you are having trouble finding an appropriate name.

var aData; - I have no idea what this array is for
var aSelectedRows; - Easy to understand

Write booleans as predicates
To make booleans easy to read in statements, we can write them as follows:

4 Practical variable naming rules
Share this