lua-users home
lua-l archive

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


在 2016/6/11 4:38, Hisham 写道:
On 10 June 2016 at 02:14, 书呆彭, Peng Yi <nerditation@outlook.com> wrote:

My reasoning for the latter is that using inconsistent, `local x =
require "y"` types of names is counterproductive: especially when
looking at someone else's code, having to keep in mind how a module
author decided to call a well-known library is an avoidable extra
cognitive load, and having to skim back and forth to look at the
require() list is annoying.

that extra cognitive load is exact my concern. besides reading others' code,
I sometimes felt it unnecessarily annoyed when search in the documents.

I'd say this was an unfortunate decision when LuaFileSystem was first written (not to
mention that the name of this library is super confusing, since
LuaFileSystem is not, well, a file system — this is not a rhetorical
point, it _did_ leave me puzzled the first time I saw the name, back
in the day).
true. it is very important to choose a proper name for a project.

even though LuaFileSystem is so widely used, and people have got to remember the
module name anyway, I see why people complain about that: when I was trying
the API of LuaFileSystem, I typed `require 'luafilesystem'` in the interactive
interpreter session; that was my expectation for a module installed via
`luarocks install luafilesystem`.

So, in short, the way I try to do things is to keep it simple:

project Foo, rockspec foo, local foo = require("foo")

I think it's the path of least surprise for users of the project. :)

thanks, I'll try to comply with it. it is really good practice.



another common case is how to name bindings to other libraries? suppose there is
a C library dealing with yaml named libyaml2 (I just made up this name, I didn't
check whether there is really such a library), which project name would you choose
for a Lua binding to that library: LuaLibyaml2, LLibyaml2, Lua-Libyaml2, LuaYaml2,
LYaml2, yaml2Lua or libyaml2lua, or something else?

also, what about the module name to give `require`: yaml2, lyaml2, luayaml2,
libyaml2, llibyaml2, lualibyaml2, libyaml2lua, or something else?

-- Hisham

--
the nerdy Peng / 书呆彭 / Sent from Thunderbird