Spaces in filenames are a problem which is as known as enervating
hm, historically, you're right, but honestly, haven't had a problem with spaces in file names since ca. 2001. You bring up the right points:
When calling a command-line tool, remember to quote the file name, if this is allowed.
It's always allowed.
Especially, don't forget to quote it when referring to the tool via a program. (pseudocode e. g.
execute "commandlinetool -r '" <> filename <> "'")
Sure! I'd put this guideline very high. It's essentially as good as "if dealing with integers, accept that they might be 0 or even negative". So, write non-broken software, which accepts all valid inputs. People have mostly gotten around to doing that, it's gotten pretty rare a sight to see scripts doing this incorrectly outside of small private projects.
Some command line tools offer options to prevent errors by having spaces in filenames
Yup. That goes under the aspect of "don't write broken software" above: A space is a valid character in a file name and has been on most operating systems latest starting 1995. If your program/script assumes it can not occur in a file name, you're doing it wrong, and you've got the idea somehow planted in your head that this is a valid assumption.
I'll argue most younger developers will not even have that assumption!
While programming, pay attention to the type, order, and number of command line arguments and fail fast, if these checks fail.
Now, that is called defensive programming. In many cases, it's a good idea, in others, it's OK to just fail at some random point and reflect that failure one level up. As in "cannot connect to brain surgery robot"; there's no reason the person pushing a button would want to know that it failed because some config file had the wrong characters in it, or whatever.
Note that sensible error handling is really not a strength of any shell scripting language I'm aware of. Things are decades (like, 3) behind other languages (Python has some passable exception handling, so does C++, or Java, or Rust, or… basically most languages today aren't as terrible as zsh, or worse, bash, ksh, csh, …)
pay attention to the type
You might be on to something here: shell scripting languages universally are quite bad at handling different types as different, incompatible things. That's by design, because they're supposed to plug everything into everything, easily, more than provably correctly.
So, maybe, a language with at least some notion and tools to check types would be better (e.g. Python), or using something that actually has a stricter type system but is not as hazardous and hard to write as C, C++ or Rust might be the way to go (e.g. Go, but I have zero experience with that).
It is rather elaborate to use make with spaces
Correct. I have nothing to add to this, other than that I consider make to have stalled since the early 1990s, and is, albeit it's such a crucially important software supply chain element, woefully under-robust.
You rarely write your own Makefiles these days: In times where you always need a pre-build configure system to figure out compiler options and library locations, that's generated by that system. Most such systems these days support less broken things than Makefiles as build tools. I do actually like
meson and a few other pre-build configure frameworks support generating ninja files instead of Makefiles, out of the box. So do that. (Note that using said tools, they will probably generate Makefiles that work even with files with spaces, but it's just not a very reliable thing; I've witnessed a 4 h automotive linux distro build fail because a Make update meant the canonical way spaces can be inserted into Make variables was removed. The dev that needed to fix that earned a lot of respect that day from my side, and a bit of debugging help that led him to find that bug. Great outlooks!)
Test programs with spaces in filenames as input and execute the program as well as its test suite within a directory whose name contains spaces.
Yes, but again, this is just "normal development", as in "don't assume spaces in file names can't happen, why would you even assume that?!".
So, my main takeaway for a strategy is:
- Whatever you do, don't assume at any point that a space in a file name doesn't happen. It's a bogus assumption, which was never in your career a valid one to make.
- Avoid tools that assume the same.