Nmap Development mailing list archives
Re: [NSE] Locals, Globals, and You (ALL script writers please read)
From: Patrick Donnelly <batrick () batbytes com>
Date: Sun, 15 Aug 2010 21:36:41 -0400
On Sat, Aug 14, 2010 at 11:32 PM, Ron <ron () skullsecurity net> wrote:
One thing I run into is situations where I use the same variable (like status) multiple times, but use a different variable alongside. For example: status, variable1 = function1() status, variable2 = function2() status, variable3 = function3() There doesn't seem to be a clean way to do that, unless it's okay to re-declare status as local: local status, variable1 = function1() local status, variable2 = function2() ...
This *is* ok. There's nothing wrong with it except each new declaration of status (when declared in the same block) will use up a new register. This will almost certainly not cause problems unless you use the maximum number of registers (~250). I would say go ahead and do it.
That's when I start declaring stuff at the top of the function. It gets even worse when I need to use the return value of 'status' in a call to the next function, because then you're re-declaring it and using it on the same line and that's all kinds of not good.
Like I said above, it's ok to do. It's neither good nor bad.
I know you have a script that'll find accidental global accesses. And that's good, because I've spent a lot of time tracking down nasty bugs that are caused by exactly that (accidental globals). But is there any way to make it easier to run your script? Like, even if it can't be automated (nmap --script-check-globals?), at least including it in Nmap or something? I wish Lua wouldn't even let you declare a global within a function. I like Ruby's style better, of using @@blah for a global, to totally differentiate it.
It's a useful script but I'd prefer to fix the habits that help cause the problems.
On a related note, I'm pretty sure there's currently no "style guide" for writing scripts, and I'm sure that if you took the 5 people who write the most scripts, none of them would agree on proper styles (even things like whitespace, comments, variable declarations, etc). But maybe we should start looking into building a style guide.
This is a good idea. -- - Patrick Donnelly _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://seclists.org/nmap-dev/
Current thread:
- [NSE] Locals, Globals, and You (ALL script writers please read) Patrick Donnelly (Aug 14)
- Re: [NSE] Locals, Globals, and You (ALL script writers please read) Ron (Aug 14)
- Re: [NSE] Locals, Globals, and You (ALL script writers please read) Patrick Donnelly (Aug 15)
- Re: [NSE] Locals, Globals, and You (ALL script writers please read) Ron (Aug 14)