lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

On 8/17/05, Chris Marrin <chris@marrin.com> wrote:
> Vijay Aswadhati wrote:
> >>import "a.b.c"
> >>    ==>
> >>local c = require "a.b.c"
> >>
> >>import("a.b.c", d, e, f)
> >>    ==>
> >>local c = require "a.b.c"
> >>local d, e, f = c.d, c.e, c.f
> >>
> >>Realistic examples:
> >>
> >>import("math", sin, cos, tan)
> >>import("string", sub, gsub, find, gfind)
> >>
> >
> >
> > Very very nice syntax; This is a 'fits like a glove' proposal methinks. I
> > vaguely remember see this as a feature of Python.
> 
> The one nice feature that Python has is:
> 
>      from math import *
> 

Iirc, in the python community, this is generally not encouraged since
it makes things less clear. eg:

from foo import *
from bar import *
from baz import *

blob.do(x)

-- where does blob come from? If you were a second generation
maintainer of the code, and not familiar with the imported libs, you'd
have to go through all of them to find where blob comes from. (sure,
we have grep, but it's still tedious)
-- what if both foo and bar have the name blob in them? (I forget what
python does)

Personally, I never do the "import *" thing.

I love the proposed:
import("foo")

to import the module foo into the local namespace
and:
import("foo", blob, blip)

to get blob and blip from module foo. I also like very much if, as
Rici said, even standard modules need
import("math")

to be consistant.

I guess I subscribe to the explicit better than implicit school...

The slightly different behaviour of require as used by different lua
module authors (as described by an earlier poster in this thread) also
got me confused when I was starting out with lua - I'm sure it would
trip other newbies too.

-- 
Regards,

Mukhsein