lua-users home
lua-l archive

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


On 2012-09-28 4:39 AM, "Thijs Schreijer" <thijs@thijsschreijer.nl> wrote:
>
> > -----Original Message-----
> > From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
> > On Behalf Of steve donovan
> > Sent: vrijdag 28 september 2012 10:12
> > To: Lua mailing list
> > Subject: Re: require() multiple parameters
> >
> > On Fri, Sep 28, 2012 at 9:52 AM, Thijs Schreijer
> > <thijs@thijsschreijer.nl> wrote:
> > > One thing that comes to mind is how to handle errors; in the example,
> > > if 'butter' either isn't available or throws an error, what to return
> > then?
> >
> > That's probably a good answer to your original question ;)  Although I
> > think we can assume that loading modules should fail in a noisy way by
> > throwing an error, hence the old pcall(require,'mod') trick.  I would
> > _not_ expect require() to return me an error message!
> >
> > steve d.
>
> Not my question :) but I agree that it seems a reason to keep it as it is.
>
>
>

I would assume if "butter" is not available or otherwise fails to load, require() throws an error... Probably in 98% of cases if any module is missing you want to bail out. If not, you can try again - since require() caches objects, you can look at package.loaded to see which modules did load, or just repeat the process.

Of course it's trivial to provide your own version that does this, but then your programs still have two require() calls, which looks a bit silly.
require("multi_require")
require("bread", "butter", "jelly")
plus to me, it seems silly to bring in another library (and thus another dependency) just for that... Maybe if you wrote some library that provides a number of useful module-related features, that could fit in. (or copy the code into every program and hope you never want to change it.)

To me it just seems like one of those cases where a small tweak makes programs more readable (fewer require statements -> less repetition), but any means of implementing it other than as a patch to the standard library end up outweighing the benefits. Also when something is implemented as a patch (assuming it gets merged into the official builds), it becomes standard behaviour everywhere and gets documented in the manual, so you don't have people getting confused. "What does this library/function do" "I didn't know require accepted multiple values" "why isn't require accepting multiple values like it does in the platform I first used Lua on" etc...

But there's probably still a problem I haven't thought of yet that would make this not such a desirable change.