Replies: 2 comments 2 replies
-
That's quite an impressive list: I think some of it is to me at least more-or-less implicit :)
I'm a LaTeX programmer, so tabs just become spaces anyway ;)
I'm not sure what you mean here: documentation should be in the
The only capitalised variable I've ever seen in Lua code is
This is from PiL, so I think is a completely standard Lua idiom.
I've been a bit inconsistent here: trying to find what looks best!
I think I started with a space after
Huh?
I'm not keen on that myself, but then I also find Lua's
Probably just me: I really don't like the
Fine with me: mainly lacking due to oversight early on. |
Beta Was this translation helpful? Give feedback.
-
About the Sometimes Lua syntax goes against cultural intuition, for example
is a shorcut to
One would expect to end up with
but more importantly, tuple assignment is required to catch the output of the match command when there are more than one capture groups. |
Beta Was this translation helpful? Give feedback.
-
The source code follows some implicit guidelines, more or less respectfully. They are outlined here along with some complements and will eventually end up somewhere in the repository.
Notice that the following aims to cover only the backend, not the user interface (what is defined by
l3build.dtx
).Notice that this is more about better practice than definitive rules. An author may deliberately choose different practice because it serves his purpose more efficiently, this should be honored as far as possible. [ADDED]
These guidelines will motivate some cosmetic changes in order to both help the reading and avoid some kind of inconsistencies. Cosmetics is the subject of the next section. The other section will be devoted to code design, it is actually WIP.
NB: I opened the discussion without knowing issue#135.
Cosmetics
General rules
--
starts inline comments---
starts documentation commentsThe documentation for the frontend belongs to
l3build.dtx
whereas the documentation for the backend is inlinedand concerns the developers.
Roughly speaking the backend is everything that is not documented in the
l3build.dtx
.Naming convention
_
is reserved for a dummy variable (a variable that must be declared but is never used)Notice that identifiers with two leading underscores and MACRO_CASE identifiers with one leading underscore are reserved by the system.
Variable names are chosen to reflect what they are modeling.
One letter variable identifiers should be limited to short scopes, typically those which entirely fit within one screen. [ADDED]
Syntax shortcuts
dir = dir or "."
forif not dir then dir = "." end
This is usual practice, see PIL.
foo("bar")
instead offoo "bar"
, [ADDED]Indentation and breaks
The lines in a block are indented one level deeper relative to the container.
Branch and loop
if
blocks with long conditionals should separate clearly the body from the condition.The same holds for loops. For that
do
andthen
keywords can be placed on their own line,for example
could be replaced by
long lines
It might be advisable to align material vertically, in particular for long function calls and string concatenation:
Notice that line breaks correspond here to each new
-...
option.Also, the trailing
)
indicates the end of the last instruction with the same indentation.Horizontal space
Space is necessary to separate code atoms whereas too much space may render the code difficult to read.
Adopting LaTeX3 point of view seems reasonable.
In general:
If it does not widen the lines too much:
Vertical space
;
operator allows to group related instructions on one single line as an atom and should be used sparinglyFor example, to iterate over the characters of the string
str
, one may need awhile
loop instead of afor
loopUsing
;
makes sense here because the looping instructions were gathered on one line.quoting material
print
and less\n
)tables
{}
for void tables (like \TeX{} void groups){ sourcefiledir, docfiledir }
for lists{ foo: ... }
replaces{ ["foo"]: ... }
foo.bar
replacesfoo["bar"]
The long syntax is used for the global
options
table to emphasize that field names are exactly command line option names. [ADDED]Code design
build*.lua
may also returnnil
instead of 0 on proper termination. [ADDED]Naming variables
type
The variable name can include an indication of the variable type when it is not easily guessed.
For example
name
is a string andname_list
is a table array of strings.i
,j
,k
are reserved for integers.n
stands for name.Function declaration, function call
When a function declaration relies on formal arguments, then the corresponding function calls should use the same names.
In case of conflicting situation, appending or prepending some identifier to the argument name can make things more clear. With declaration
one can call
File related
Files are covered by 3 kinds of variables: the file name, the file handle and the file content.
The file name is covered by variables named containing
file
,f
orname
.The file handle is covered by
fh
or any variable named with a_fh
suffix.The file contents is referenced by any reasonably named variable.
Usage
file
base
name
dir
path
Paths
Paths are strings meant to represent some location on the file system.
Supported file systems are Windows and various unix including Apple's OS X.
To ensure cross platform compatibility, only regular files and directories are supported.
Symbolic links, desktop shortcuts and aliases are not supported.
The path separator in
texlua
is "/" but when talking to the host system it must be adapted.Beta Was this translation helpful? Give feedback.
All reactions