tomtom / ttodo_vim

Edit, view, filter, and sort todo.txt files
http://www.vim.org/scripts/script.php?script_id=5262
GNU General Public License v3.0
14 stars 1 forks source link

concept for calculation of a task's id #9

Closed nnako closed 1 year ago

nnako commented 1 year ago

ttodo provides a feature to create an "id string" for any task listed within the current task file. When in NORMAL mode, such a task's id can be created by pressing <localleader>ti or issuing a :call ttodo#ftplugin#AddId( <count> ).

In order to evaluate the "stability" and "universalit" of a task's id, I would be interested in knowing how exactly such a task id is calculated internally. As there are many possibilities to grab aspects of real life in order to set such an id, which ones did you pick and how did you combine them to generate the id string?:

combining a subset of these options (or completely other aspects) could ensure a good and stable task id which is not found anywhere else within that scope.

could you describe the implemented concept?

tomtom commented 1 year ago

The ID is calculated in s:EnsureIdAtLine() (in ftplugin.vim). If you use vim >= 8, the id is based on reltimestr(reltime()). The resulting number is then encoded as a string with base 62 using tlib#number#ConvertBase(). This procedure would fail if 2+ IDs were created in the same microsecond.

Before vim8, I used the task structure converted to a string and encoded with a homebrewn Adler 32 function.

One should keep in mind that the main goal of the ID is to reconstruct dependencies from the archive file (done.txt) for a given todo.txt file. As such it has to be unique only for a given todo.txt file (and its user). While it should be possible to define dependencies in todo.txt based on the ID, I have never actually used it this way. In todo.txt, I use indented tasks for that.

The ID should be unique at the time of creation. Once a task got an ID assigned to, the ID is not supposed to be changed. The ID is not meant to be unique across machines, users, todo files etc.

tomtom commented 1 year ago

And the ID should be as short as possible and consist only of alhpanumeric characters.

nnako commented 1 year ago

Hi @tomtom . Thanks for clarification. I use the todotxt format in an environment, where there are multiple people working simultaneously on different and even the same todo files, shared via a common file-based synchronization method like NextCloud. Potentially 1000 people working in collaboration within a shared project. This environment makes it rather possible to accidentally hit the same microsecond when creating a new task on one of the multiple task files. So, I personally like the former concept better, where you created an id in dependence of the task's textual content rather than a timestamp alone.

And the ID should be as short as possible and consist only of alhpanumeric characters.

That is a good requirement for short, human-readable text lines. And it is rather pleasing to the eye ;-) .

The ID should be unique at the time of creation. Once a task got an ID assigned to, the ID is not supposed to be changed.

That should be common practice for any task management system. Even if tasks are completed and transferred to the done file, their ID shouldn't be reusable within the same project.

The ID is not meant to be unique across machines, users, todo files etc.

In my environment, the ID sould rather be exactly that. unique as far as possible.

How come, you changed the concept for id calculation for vim >= 8? Were you forced by some technical issues? Or does the new id calculation concept promise a smaller probability for collisions? Would it be possible to maybe offer both concepts (selectable via a configuration parameter)? Or maybe combine them for even lesser collision probability?

tomtom commented 1 year ago

The change wasn't forced. It was a matter of taste. You can now choose how IDs are generated and append a (possibly user-specific) suffix.