Hacker News new | ask | show | jobs
by eecks 3443 days ago
I always name my variables descriptive names. For example, if I am in a loop and the variable represents a "record" I will name it record rather than r.

It's much more readable and you're less likely to get name clashes with other functions (r could be lots of things (even in the same file) - render, record, row, red, right)

2 comments

I always go with plural for lists and singular for iteration variables.

  for (let thing of things) {...}
Personally I have a habit of avoiding that, especially in dynamic languages, because a single typo could have nasty consequences there. So I always figure out a synonym, or use a name for the variable that's either more descriptive:

  for (let particularThing of things)
or at least visibly different:

  for (let th of thigns)
The dynamic languages I primarily use are TypeScript and Dart. I always have enough type information floating around to catch this kind of thing. But even in JavaScript it wouldn't be much of an issue since it will instantly explode on the first run, which is certainly inconvenient, but nothing major.
If you name a variable with broad scope "record", though, you deserve hell.