Choosing a programming language

There are five platforms in common usage in 2020. On traditional computing platforms, we see Windows, Linux and MacOS. For mobile we have Android and iOS. Other platforms exist, but they have negligible usage (e.g., various BSD variants and quixotic efforts at creating a third OS for mobile). Of these, iOS is the most restricted in its options for a development language. If we were to put aside iOS, I would likely choose a JVM-based language if only because I spend my days writing Java code and I know it well.

But I’m an Apple guy. I have a MacBook Pro on my lap, a Mac Mini on my desk, an iPhone in my pocket and an iPad at my side. I’ll be doing all my development on my Mac and that will be the first target for finl and what I’ll use as my reference implementation. I’m be tempted to write the code in Swift a language with which I’ve dabbled, but I suspect that it retains some of the unusual aspects of Objective C (most notably the method dispatch) which could make it challenging to integrate with applications written in other languages. For example, calling C++ from Java is well-defined, but calling Swift from Java requires creating a C wrapper around the Swift code

Given my desire for finl to be usable as a library by other applications, it looks like C++ is the best way forward (the only other option is to write in C which feels like it would be a hard pill to swallow in 2020 for application development). On the plus side, there are robust libraries for many of the features we want to work with, most notably ICU4C which seems like it will be essential for dealing with unicode text (and also finding candidate line breaks in text that doesn’t use western standards of inter-word spacing such as Amharic or East-Asian Han-based scripts). It does mean I need to bring myself 20 years up to date on the state of C++ (I attempted to write one C++ program in 2005 only to discover that the language had already changed enough to make my skills at the language partially obsolete). This is going to slow things down considerably versus writing code in a JVM-based language, but I’m up for the challenge.

Why finl? A manifesto

In 1994, LaTeX2e was released as a transitional step towards LaTeX 3. 26 years later, there still isn’t a 1.0 release of LaTeX 3. In the interim, we’ve seen the rise of HTML and the web, the dominance of PDF as a format for representation of printed material (and now there is a plan to have PDF extended with “liquid mode” that allows reflowing of PDF text for smaller screens).

In the meantime, the TeX engine has been extended multiple times, the little-used TeX-XeT, some early efforts to support large Asian character sets, and we have in widish use pdfTeX, XeTeX, LuaTeX along with an assortment of abandoned engines. Worst of all, it seems that none of pdfTeX, XeTeX or LuaTeX can serve as the one TeX to rule them all, each with some limitations that can require users to switch engines depending on their needs.

As I’ve thought about it, the problem at its root is TeX itself. It’s what would be referred to in contemporary software engineering parlance, as a tightly-coupled monolith. Worse still, it’s a tightly-coupled monolith with numerous compromises baked in because of the limitations of 1970s computing hardware. It seems that the vast majority of what work has been done with LaTeX 3 has been geared towards dealing with the limitations of TeX as a programming language.

On top of that, there’s been an explosion of questionable, if not outright harmful practices from the greater LaTeX community. Ideally, a document should be translated from one document class to another structurally similar class (naming-wise, the choice of “class” to name document classes is unfortunate, but understandable) should not require changing anything after the preamble, better still, nothing but the \documentclass command itself. All the appearance should be handled through the document class and packages should be employed to provide document structure enhancements or new capabilities). There are numerous violations of this. The memoir class is a mess, claiming to be a replacement for article, report and book (this reminds me of the mess that’s PHP where the same data structure acts as an array and an associative array and as a consequence manages to merge the worst aspects of both in one inefficient construct) and at the same time, providing a number of bits of functionality that belong in packages rather than the document class. On the flipside, packages like geometry and fancyhdr fall into a category that LaTeX2e doesn’t really define, bits of common code that would be helpful to document class writers but shouldn’t really be exposed to document authors.

So what can be done? I believe a complete rethink of LaTeX is necessary. The macro-based language of LaTeX is intellectually satisfying in many of the same ways that solving a sudoku puzzle or playing chess can be. It is not, however, a straightforward programming model and does not conform to any popular paradigm (I don’t think any other programming language is of similar structure). It’s time to separate out the language for formatting the document from the language for writing the document, to make a clear break between extensions that modify appearance from extensions that provide new functionality.

While we’re at it, a number of other TeX limitations need to be done away with. TeX was written with the needs of typesetting The Art of Computer Programming and so doesn’t handle complicated page layouts well and for all its valiant efforts, this has impacted LaTeX. Multi-column layouts are painful, float handling is a mess, some things that designers expect to be able to do, like specifying baseline-to-baseline skips or forcing text onto grid lines are difficult if not impossible.

Unicode needs to be a first-class citizen. There’s no reason in 2020 for a document writer to have to type \’a instead of á in a document. UTF-8 is the new 7-bit ASCII.

The code of the engine should be decoupled. Why shouldn’t any application that is willing to interface with the code be able to directly access the parser or the paragraph layout engine or the math layout engine? Imagine if a user of Word could access a plugin that let her type \sum_{i=0}^{\infty} \frac{1}{2^{i}} or even ∑_{i=0}^{∞} \frac{1}{2^{i}} or selecting these symbols via GUI into a low-level token stream to get

sum from 0 to infinity of 1/2^i

in her document. Imagine if a document could be painlessly transformed into HTML or even (unicode) plain text because the page layout and formatting engines are decoupled enough to manage such things.