Also, i personally feel that it is often confusing not to know what type of
value we're dealing with here. I wonder if this never occured to anyone
before because almost all scripts i look at don't follow any variable naming
convention at all. A variable "index" could be an integer, a string, or even
a table. This isn't clear without looking at the context, and that makes
reading (especially complex) scripts harder than it need be.
I've come up with a simple scheme for naming my variables which i've sticked
to for like 50.000 lines of Lua code:
nNumber = 123
iInteger = 123 or rReal = 1.23 to differentiate where needed
sString = "a string"
bBoolean = true
tTable = {}
uUserdata = <someuserdata>
fFunction = function f() end
cCoroutine = co
hThread = <thread>
xUnknown (for values whose type is determined at runtime, eg a table index
can be both a string and an integer when walking through table elements)
Giving variables reasonable names (and prefixed) seems to be neglected far
too often in the Lua community, if i may say so. I often find it hard to
read scripts as i have to keep in mind one extra information about each
variable: it's type. If i can't remember, I'll have to go back and scan
through the relevant parts again, eg looking up the type of value a function
returns. And then back again to where i was. ... Where was I? <sigh>
Sure, it's quicker to write everything in lowercase letters and stick to
variable names with at max 6 chars. Sure, it's hard to stick or even get
used to naming conventions when many Lua scripts are at most 200 lines. Yes,
i *felt* that, too. But it would still make it easier to understand the
scripts, even for the scripter (my personal experience tells me so).