TUGboat, Volume 32 (2011), No. 3 321
sion. Since other package developers may need to
tweak your code for compatibility reasons, it is bet-
ter to let them work on small chunks rather than big
ones.
To illustrate this, let us mention the case of
C
u
rV
e
in which, at some point, we decided to sup-
port the
splitbib
package. In order to do so, we
needed to override some parts of
splitbib
’s macro
\NMSB@writeentry
. This macro was originally 203
lines long. After dead branch removal, that is, after
cutting out pieces of code that we knew would never
be executed in the context of
C
u
rV
e
, we ended up
with 156 lines that needed to be imported into
C
u
rV
e
,
only to modify 5 of them. Our modifications conse-
quently involve only 3% of the code that needed to
be imported. One can easily imagine how bad this is
in terms of maintainability. We need to keep track
of potential modifications on 203 lines of
splitbib
just to make sure our 5 keep functioning correctly.
4 Level 3: Behavior
In the previous section, we claimed to be more con-
cerned with how to implement particular features,
rather than the features themselves. In this section,
we focus on features through the lens of behavior.
What we are interested in is the impact of your pack-
age features on the people that may interact with it.
4.1 Rule #1: Be user-friendly
The first category of people who will interact with
your package is its end users. Hopefully, you belong
to this category as well. There is, however, one major
difference between you and other users: you know the
package much better than they do, since you wrote it.
Being user-friendly means doing everything possible
to make your package easy to use. This can mean
many different things, but two important aspects are
documentation and backward compatibility.
4.1.1 Documentation
Nowadays, the vast majority of L
A
T
E
X packages comes
with documentation. The combination of
doc
,
ltxdoc
and
docstrip
, by allowing for literate programming,
has greatly helped the community in this respect.
Nevertheless, there remains a huge difference between
documentation and good documentation.
The difficulty in writing good documentation is
to put yourself in the position of the casual user —
which you are not because you know the package
so well already. Thinking from a user perspective is
probably the most difficult thing to do, but it can
also be a very rewarding experience (we will get back
to this later).
One of the major pitfalls to avoid when writing
documentation is forgetting that a user manual is not
the same thing as a reference manual. Just doing lit-
erate programming is not enough. Documenting your
macros around their implementation is not enough.
The casual user is not interested in the brute list of
commands, nor in the internals of your package. The
casual user wants an overview of the package, what it
is for, what it can do, what it can’t, probably a quick
start guide describing the entry points and the de-
fault behavior, with examples. Only then, when the
major concepts are understood, you may delve into
complexity and start talking about customization,
additional but less important features, and so on.
A good user manual will sacrifice sufficiency
to the benefit of gradualness and redundancy. You
shouldn’t be afraid of lying by omission to the readers.
It is for their own good. They don’t want to be
overwhelmed by information. A typical hint that you
are reading a bad manual is when the documentation
starts with the full list of package options. There
is no point in introducing an option dealing with
a concept that the reader does not understand yet
(that would be a reference manual). Another hint is
when a manual starts referring to another package
(that it happens to use internally) and assumes that
the reader knows everything about it already. The
end user shouldn’t have to read two or three other
manuals to understand yours, especially if in the end,
they will never use those other packages directly.
Why, as we said earlier, can it be rewarding to
write a good manual? Because writing documenta-
tion is in fact a feedback loop. The difficult thing,
again, is to put yourself in the position of someone
who knows nothing about the things you are going
to talk about, and ask yourself: “what do I need
to say first?” If you can do that, you will discover
that many times, the answers to that question reveal
design flaws in your package, its design or its APIs.
Things that a casual user would want to do but can’t,
things that should be simple to do but aren’t, de-
fault behavior that shouldn’t be by default, concepts
that are not apparent enough, not distinct enough,
names that are not sufficiently self-explanatory. Etc.
other words, writing or improving the quality of your
manual often helps you improve the quality of your
code, and vice-versa.
4.1.2 Backward compatibility
Documentation is an important feature. Backward
compatibility is another. Users can get very frus-
trated when a package breaks their documents from
one version to another, or more generally, when a
document doesn’t compile anymore after a couple
Towards L
A
T
E
X coding standards