[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: some random thoughts on naming conventions for Lua libraries/modules
- From: 书呆彭, Peng Yi <nerditation@...>
- Date: Fri, 10 Jun 2016 13:14:45 +0800
there are various kinds of Lua libraries(just to say some, incomplete, of course):
* binding to other libraries/runtimes/APIs written in other languages (C/C++/Go/dotNet etc.).
e.g. wxLua, Lua-SDL2, LGI, LuaCOM, LuaInterface, lposix, etc.
* rewrite/resemble/reimplement of libraries written in other languages.
e.g. LuaUnit, alt-getopt, lustache, lspec, markdown.lua[https://github.com/mpeterv/markdown], etc.
* Lua special or Lua centric libraries (including compatibility backport libraries).
e.g. lpeg, strictness, penlight, lualanes, 30log, bit32, compat52, etc.
* frameworks and applications which are implemented and can be used as libraries.
e.g. lake, moonscript, lapis, etc.
looking at these libraries, I find the names are inconsistent, among which I think some are
due to technical restrictions, some are simply arbitrarily chosen.
for library/project names (usually the name you give luarocks to install), there exists:
XXX, Lua-XXX, lua-XXX, luaXXX, lXXX, LXXX, XXXLua, XXX-Lua, etc.
for module names (that is, the parameter you passed to `require`), there exists:
xxx, lxxx, luaxxx, xxxlua, etc.
and for some projects, the namespace for functions, variables and constants in the document
is inconsistent with (sometimes even wrong) the module name.
for example,
IUPLua -> (no luarock) -> local iup = require 'iuplua'
wxLua -> (no luarock) -> local wx = require 'wx'
Lua-SDL2 -> luarocks install lua-sdl2 -> local SDL = require 'SDL'
LuaFileSystem -> luarocks install luafilesystem -> local lfs = require 'lfs'
LuaGL -> luarocks install luagl -> local gl = require 'luagl'
I am NOT suggesting any naming schema or guidelines here. I have my personal taste too.
I don't mean to start a debate, or even a war about this. I am just curious about what's
other people's opinions on this topic. this helps me to choose names when I release
my code to the public.
currently my personal preference is roughly like such:
when I write a binding to library Foo, I would choose FooLua as library name (like wxLua and IUPLua).
I would prefer `require 'foo'` (like wx) unless there is conflict of dll/so filenames, in which case
I would use `require 'foolua'` (like iuplua).
when I write a general purpose library for Lua, I would name it LuaFooBar, and `require 'foobar'`.
and I like write application Foo as a thin layer upon a library FooLib. using `require 'foolib'`.
what's your opinion?
--
the nerdy Peng / 书呆彭 / Sent from Thunderbird