DEV Community

Discussion on: What conventional wisdom in software is wrong?

Collapse
 
thojest profile image
thojest

That you always have to put extremly verbose and meaningful variable names. In general yes!

But it depends on the scope of the variable.

There is nothing wrong to use variable names like 'el' or 'num' in lambda functions like e.g. foreach(el => ...)

Collapse
 
guitarino profile image
Kirill Shestakov • Edited

Why not? I'd rather see a meaningful variable name that describes its purpose rather than something generic that I have to figure out on my own.

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

It all depends on your language's conventions. I've often seen these be standard, many coming from mathematics itself:

  • i, j: indices, loop control variables (no lifetime beyond context).
  • x, y, n: temporary variables in algorithm (no lifetime beyond algorithm)
  • n, num: temporary "number", such as an accumulator or the current value when iterating over numbers (no lifetime beyond context).
  • v, val: temporary value, usually from iteration (no lifetime beyond context)
  • x, y, z: coordinates (meaning from context).
  • len: length
  • iter, it: iterator

Beyond that, you should probably write real names.

Collapse
 
metalmikester profile image
Michel Renaud

That depends on what the loop, temp var (etc.) does. Sometimes having a meaningless name like that is perfectly fine, something you need something more descriptive as it may help read what's being done more easily (I just coded a case like that this morning).