I’ve been trying to basically build a library that helps you put together a distribution archive.
And my initial plan for the API looked something like this:
Distribution::new("my-program")
.dir("assets")
.file("favicon.png", |path| build_favicon(path)); // "|path| ..." is a lambda function that gets the target path passed in
So, it would allow you to define the file structure, and for the parts that actually need to be built, you’d provide a lambda function, which it would automatically run or not, depending on whether the inputs changed.
Right, inputs, what are those? I kind of need my user to tell me. So, I decided to implement the caching as a separate API, which you would call on your own when you get called by the lambda function.
Then I realized, I kind of don’t need the lambda function then. I could just construct file paths and then my user calls their build_favicon(...)
function or similar on their own.
There is just one crucial problem with that. This is what the path API in the stdlib looks like:
PathBuf::new("my-program")
.join("assets")
.join("favicon.png");
I might not have built anything, really. 🫠
That’s supposed to be “impractical”, not “in practice”, for others reading along.
For example, the “proper” command to list a directory is:
Get-ChildItem
The “proper” command to fetch a webpage is:
Invoke-WebRequest https://example.com/
In these particular cases, they do have aliases defined, so you can use
ls
,dir
andcurl
instead, but …yeah, that’s still generally what the command names are like.It’s partially more verbose than C#, which is one of the most verbose programming languages out there. I genuinely feel like this kind of defeats the point of having a scripting language in the first place, when it isn’t succinct.
Like, you’re hardly going to use it interactively, because it is so verbose, so you won’t know the commands very well. Which means, if you go to write a script with Powershell, you’ll need to look up how to do everything just as much as with a full-fledged programming language. And I do typically prefer the better tooling of a full-fledged programming language…