-
Notifications
You must be signed in to change notification settings - Fork 33
Implementation
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.
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.
The standard config parser in Nim is provided by the parsecfg module.
It supports basic .ini
-style config files with sections.
Regular expression support in Nim is provided by the module re, which is a wrapper around the PCRE C-library.
The osproc standard module of Nim implements advanced functionality for executing OS processes and process communication.
The os standard module of Nim allows retrieving environment variables.