DEV Community

Discussion on: What conventional wisdom in software is wrong?

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).