Skip to content
Johannes Schlatow edited this page Mar 18, 2021 · 2 revisions

Taskopen 2.0 Implementation Notes

The initial idea was to use Python instead of Perl for taskopen 2.0 because it produces cleaner code and thus simplifies contributions. Python also comes pre-installed on many distributions. Yet, Python has two main drawbacks for this use case.

First and foremost, Python (3) is not well suited for small and frequently called command line tools. The basic interpreted already loads a plethora of modules which increases startup time significantly. I have run a small test on my machine by starting an empty Python script 1000 times. On average, the startup time of this Python script already took 25ms. This is comparitively large compared to Perl, which took 1.3ms on average in the same test scenario. The perl implementation of taskopen took 88ms on average (including calls to taskwarrior) on 31 actionable annotations. A major increase in execution time would not be accetable as it would result in noticable delays.

The second drawback of Python is the variety of versions on different distributions, which increases maintenance efforts.

Test Average Time over 1000 executions
Startup time Python 3.9.2 25ms
Startup time Perl 5.32.1 1.3ms
Startup time nim 0.55ms
taskopen -l > /dev/null 88ms

An interesting alternative to Python is Nim, which is quite similar to Python but a compiled language with good portability. The startup times already look very promising regarding performance (see Table).

The remainder of this page should be considered as a brief research and documentation of how taskopen 2.0 can be implemented with Nim.

Command line parsing in Nim

The standard command line parser in Nim is provided by the parseopt module. Parseopt supports short and long options and positional arguments but no subcommands. Moreover, it requires manual token iteration which can be inconvenient.

A promision alternative is cligen, which is non-standard but actively maintained. Cligen supports all necessary features and comes with a very clean API as it infers the command line arguments from proc signatures.

On a second thought, some concepts of taskopen (such as a default subcommand and alias commands) might not be trivial to implement with cligen.

Configuration parsing in Nim

The standard config parser in Nim is provided by the parsecfg module. It supports basic .ini-style config files with sections.

Regular expressions in Nim

Regular expression support in Nim is provided by the module re, which is a wrapper around the PCRE C-library.

Process execution in Nim

The osproc standard module of Nim implements advanced functionality for executing OS processes and process communication.

Accessing environment variables

The os standard module of Nim allows retrieving environment variables.