[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Autolocals?
- From: Mark Hamburg <mhamburg@...>
- Date: Sat, 22 Mar 2008 00:08:11 -0700
on 3/21/08 8:17 PM, David Manura at dm.lua@math2.org wrote:
> local Corge = require 'qux.quux.Corge'
> local foo = Corge.foo
> local bar = Corge.bar
> local baz = Corge.baz
>
> There can, however, be an advantage in removing some or all of the last three
> lines and, for example, referencing "Corge.foo" rather than "foo" in the code
> since the prefix "Corge." indicates explicitly where the function "foo" comes
> from, and the Hungarian-ish prefix makes obvious the fact that "foo" is
> external
> to the current module. The "local foo = Corge.foo" is called a "static
> import"
> in a some other languages and its use is recommended only sparingly[1].
When used frequently, however, it can be a performance win since it
eliminates a table lookup. I've started to use the convention:
local Corge_foo = Corge.foo
Mark