During a recent discussion on Discord, I raised the idea of having an alternative to directories-rs in Crystal. @straight-shoota suggested that we discuss it further here and possibly include the newly added module in the standard library.
Benefits:
Consistent behavior across different operating systems. Configuration, cache, data, etc., would be accessed through a unified API without worrying about platform-specific nuances. This might benefit the compiler and Shards as well.
Promotion of best practices, whereas a Crystal developer might typically opt for a lazy solution, such as storing this data alongside the binary (which is not idiomatic on Linux and other operating systems).
It is relatively easy to implement, and almost no maintenance should be required.
Caveats:
Assuming this is going to be added, we would need to decide which directories are to be included. The bare minimum might be whatās described in the XDG Base Directory Specification.
We can probably take a lot of inspiration from the dirs-dev implementations (including directories-rs). Their authors seem to have figured out a practical API and behaviour.
Iām a bit surprised though that the XDG_* environment variables seem to be only honored on Linux. I figure they should work on any operating system (if defined by the user).
I find that odd too. Itās a freedesktop specification part of X.org, and not tied to Linux in any way. Maybe they just donāt care or forgot about UNIX in general and *BSD in particular.
Nowhere. Someone interested can start writing down a RFC to propose a Crystal API and how it each method would map to the different underlying system (UNIX, Windows, macOS) and maybe be fancy: iOS, Androidā¦