|Welcome to the Monastery|
Re^3: Coding style: truth of variable nameby roboticus (Chancellor)
|on Apr 19, 2020 at 12:16 UTC||Need Help??|
In the case of input validation, I usually let the variable name express the intent then validate the value into submission before doing the work:
In other cases when the variable isn't so clear but it will be clear shortly, I'll often use $t or $tmp for the placeholder. Then I'll give it a name or pass the data off to a better-named thing:
I don't think $t or $tmp is a great name, but finding good names is hard. I use it so that I can look at it and dispose of it ASAP.
Frequently I find I can't name something well the first time I encounter or use it. So I come up with my best guess of the name and use it. Then, when it feels like the name is wrong, and I find it doesn't fit, I do one of two things: If I have a better name in mind, I'll rename it. Sometimes, though, I can't think of a better name, so I instead give it a prefix of 'z' to "call it out". That way, when I revisit the code, I know I need a better name. Not perfect, not even good, but it usually gets me by. Yet I still wind up with stuff like:
an atrocity which came directly off my screen from last nights session.
When your only tool is a hammer, all problems look like your thumb.