Re: Packaging and importing
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Packaging and importing
- From: Mark Hamburg <mhamburg@...>
- Date: 2005年8月14日 21:02:50 -0700
One problem with having module auto-populate the global namespace is that it
encourages the creation of inefficient and fragile Lua code.
The efficient path:
local foo = require "foo"
for k = 1, 10 do
foo.bar( k )
end
The inefficient path:
require "foo"
for k = 1, 10 do
foo.bar( k )
end
The fragile path:
-- Fortunately, someone else seems to have always required foo.
for k = 1, 10 do
foo.bar( k )
end
And, to end on a positive note, the really efficient path:
local foo = require "foo"
local bar = foo.bar
for k = 1, 10 do
bar( k )
end
I don't have a good answer for how to encourage people to use the last form,
but it's a simple change to module to get them to use the first form. If
we're going to worry about Lua efficiency and how well it does on shootouts,
it might be a good idea to try to promote the writing of efficient Lua code.
Mark