Useless error messages in TeX and C++
Jonathan Fine
jfine2358 at gmail.com
Thu Jan 11 13:13:22 CET 2024
Hi
Summary: Perhaps we can learn something from C++ that will improve Latex
error messages. And we see the phrase "absolutely useless barf".
It is I think well known that errors in TeX documents are detected late
rather than early. For example
\goodmacro{this and that and \undefined}
will produce an error only AFTER \goodmacro has started executing. Worse,
if this line of code might be guarded by a conditional then not even the
\goodmacro in it is invoked. Perhaps it takes two parameters!
With complex macro packages such as Latex this can result in error messages
that are not easily comprehensible to many ordinary users. This also causes
issues regarding testing code. For example a typo in the name of an
internal macro remains undetected until a test (or a user) tries to execute
the misnamed command.
In fairness, Python again has few compile time errors. It does have syntax
errors, which are compile time. But Python's NameErrror is a run-time error.
So why mention C++ in this context. Well, a recent discussion on the Linux
Kernel Mailing List produced the wonderful phrase "absolutely useless barf
as error messages", which is surely what many authors feel when they're
suddenly dropped into the task of debugging software, or more exactly
erroneous input.
In 2014 it was proposed that the Linux kernel support modern C++ code. Not
much happened until this week. Peter Anvin wrote that C++14 was the first
version that supported "reasonable metaprogramming", but that C++20 was a
"game changer" in that it "adds concepts, which makes it possible to
actually get reasonable errors".
So there we are. The C++ templates are a form of metaprogramming. The
addition of concepts, whatever they are, turns "absolutely useless barf"
into "reasonable errors". This post is based on:
https://www.phoronix.com/news/CPP-Linux-Kernel-2024-Discuss
Perhaps this provides a framework for improving Latex error messages
(without introducing backwards incompatibilities). According to wikipedia,
concepts are named boolean predicates on template parameters, which are
evaluated AT COMPILE TIME (my emphasis). This makes them somewhat similar
to Python's type hints. And as far I know, Latex3 naming conventions also
use boolean predicates, which are however not evaluated at compile time.
Here are some links:
https://en.wikipedia.org/wiki/Concepts_(C++)
https://mypy-lang.org/
Please comment on this if you have an opinion. My thoughts on this are only
at an initial stage.
with kind regards
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/texhax/attachments/20240111/d41dc76e/attachment.htm>
More information about the texhax
mailing list.