lua-users home
lua-l archive

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

Jon Akhtar wrote:

> Is there a compelling reason for not making 'require' and 'module'
> keywords in the language.

Yes, several.

> The only reasons I can come up with is that modules (like almost
> everything in Lua) are optional, and may not be included in embedded
> Lua, and that they were built using lower level api's like setfenv.

This is one reason, but a relatively minor one.

All that follows is in my opinion, of course...

When designing a language, it is best to make the actual language core
as small as possible.  This has a number of benefits, including making
the implementation easier, quicker, and more correct.

By pushing out some language features into functions, it also makes it
easier to replace / extend / remove that functionality.

A classic example of this is when you want to sandbox Lua code.  Only
the basic language constructs can't be removed, and you don't need to,
because they confer no special power outside the sandbox.

So I can now go and replace 'require' with a version that allows only
specific modules (that I deem safe) from specific paths to be loaded.
The client code is unchanged, I don't need to disallow the 'require'
keyword, which would require changes to the parser.

The same goes for other language features.  To see the opposite of
this, look at Ada.  It has built-in support for one type of
concurrency.  Which is great, don't get me wrong.  However, if you
wanted to use something else, like Software Transactional Memory, the
language built-in constructs won't be used.  And in some cases, can
interfere with new stuff.

James Graves