2024-12-09 December Adventure 2024: Day 9

December Adventure 2024: Day 9

MyCmd: Unifying Command Group and Command Registries

Software design is messy; especially if you are working with a language constrained in its semantic toolset like Bash.

A thought occurs to me that I need to ponder: could I merge the command group and command registries into a singular concept? I think this might be worthwhile, as it would make command line parsing trivial. Maybe.

I think this is best described by looking at the scalar fields of each object. Here I’m linking to an older commit when the field names were all together for easy reference.

In a Command Group, we have:

In a Command, we have:

The only differences:

In other words, the core data structures are the same. The differences are within the operations defined on them.

MyCmd: A Virtual File System

When I was on my afternoon walk, I had the realization that what I’m implementing is essentially a virtual file system (VFS). Here’s what MyCmd does:

And if we look at the implementation of Unix-like filesystems, what is the core data structure? The index node, or inode. At a great simplification (and perhaps over-generalization), every file and directory on disk has an inode. It is the data common to both.

I’m not sure if registry is the right word now for this concept; though filesystem or VFS isn’t quite accurate either, as that is too low level. But using registry for now, I think this is what I want to implement:

Summary

I didn’t write any code today. I spent most of my day pondering these ideas. I’m still not all the way decided if this is the best way to go. It will enable me to factor the common code from the two current largest files into a common one, as well as give me a place for some common code I was putting in the top-level mycmd-lib file. Plus, when I finish my clean-ups and get to implementing command-line parsing for the MyCmd launcher, having a single data structure holding data for all items will make the querying a lot easier.

Tomorrow

I’m going to sleep on this idea and if it still feels right, I’ll attempt to create the unification of the registry and indexed item tomorrow. Naming things is hard, though.


All of my December Adventure 2024 posts will be linked from here.