DEV Community

Maggie Martin
Maggie Martin

Posted on

Variable names

I find myself being too vague when naming variables

for example
$responseData = []

I mean, it is data, and it will be include in the response. What other synonyms for data do others use?

Top comments (1)

Collapse
 
ingosteinke profile image
Ingo Steinke, web developer • Edited

If you don't mind very long variable names that can make lines so long that it could affect code readability, you could add what kind of response data it is. Some information is redundant when using types and classes, but redundancy can make it easier for other developers to understand your intentions and expectations.

$productListResponseData = []

We can probably omit the least meaningful part: "data".
Do you have any variables that don't contain data?

$productListResponse = []

We wouldn't have to call it response when it's either obvious (while fetching) or irrelevant (during further processing).

$productList = []

I tend to modify my variable names during an early explorative coding phase.

Some aspects might be added later, like when there is

$productListRawResponseJson = '';
$productListReponseData = [];
$productListFromLocalCache = [];
$productList = [];
$productListRenderedHTML = '';
Enter fullscreen mode Exit fullscreen mode

... and so on, until it gets useful and unambiguous enough that I would dare to defend it in a severe code review.