Ask coding questions

← Back to all posts
Variable Count Go Brrrrr ...
Smart0ne (723)

In code, people need variables. But sometimes (read: all the times), I need to use a lot of variables, and at the end, I worry over if people use some of the code, they don't know what it is. And I also worry, that if time passes, I won't even understand what I wrote.

I always try to use descriptive variable names (with exceptions such as in for loops), but I feel like it's not enough. Should I include comments on what every single variable is? Or is there some other way?

Comments
hotnewtop
Coder100 (16857)

no.
no you shouldn't.

variables, are SUPPOSED to be descriptive.

Comments will help describe what the value is if its a complex value that cannot be easily determined, but overall variable NAMES should do most of the heavy work.

Anyways, it's not a common problem, maybe you should https://tryitands.ee

realTronsi (914)

This usually isn't a problem unless you're abusing global variables, otherwise if you have a huge function, make sure your functions are only responsible for one thing, so variables with good naming can usually be implied.

ANDREWVOSS (36)

Descriptively naming your variables is usually enough, but you can use comments to describe variables that don't have an obvious purpose.