[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Autolocals?
- From: David Manura <dm.lua@...>
- Date: Sat, 22 Mar 2008 03:17:06 +0000 (UTC)
Alexander Gladysh writes:
>
> I [organize] each file as follows:
>
> local foo, bar, baz = import 'path/to/file.lua' { 'foo', 'bar', 'baz' }
> ...
> However there is one weak spot -- the import function. It is too easy
> to mess things up and write arguments in wrong order:
>
> local foo, bar, baz = import 'path/to/file.lua' { 'bar', 'baz', 'foo' }
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].
[1] http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html