[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Uppercase-initial globals
- From: Sean Conner <sean@...>
- Date: Wed, 22 Jun 2022 13:59:50 -0400
It was thus said that the Great Egor Skriptunoff once stated:
> A question about Lua coding style.
> Is it a good or bad idea to distinguish global from local variables by its
> uppercase / lowercase initial letter?
> Var=0 -- global
> var=0 -- local or upvalue
I don't use globals in Lua. Of the actual Lua apps that I have  none
use global variables. I do, however, do put "global" data for the app in
its own table and make it available via require() (usually, require("CONF"))
so I don't have to pass it around everywhere.
I've also cut down on my use of global variables in C, and when I do have
a global variable, it starts with a 'g', for example, 'g_L' for a global Lua
state. If it's meant to be read-only, I'll prefix it with 'c', for example,
'c_numaflinks' . For static variables outside of a function, I'll prefix
the variable with 'm' (it makes sense for me).
 Gemini server: https://github.com/spc476/GLV-1.12556
Gopher server: https://github.com/spc476/port70
I also have a 6809 assembler in Lua that's currently unpublished.
 Example: https://github.com/spc476/mod_blog/blob/master/src/globals.h