Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I got used to naming files/folders with leading zeros when I want them to be sorted alphabetically (for example payslips/invoices, etc).

But I'm a tech guy, I know what does "alphabetically" mean in the tech world. And it probably is not what common folks mean when they think "alphabetically" outside the tech world.

Edit: in fact, if I recall correctly, the proper term for this kind of sort (the one OP wants) is alphanumeric sort.



I also got used to it, but especially when writing short scripts that generate numbered files it gets annoying to have to pad with zeroes every time, and also precommit to a specific amount of digits you want to allow (finding a compromise between adding a ridiculous amount, like 20, and using only 4 despite knowing the script might one day surpass 10⁵ files).

The natural numbers are ordered. Let me use its ordering instead of having to rely on an ad-hoc lexicographic fixed-length tuple representation of decimal digits, without any padding. My position is that numbers in filenames should always be considered atomically unless explicitly instructed otherwise.

If there were no issues of backwards compatibility, I would thus advocate for changing ls. Eza (maintained fork of Exa, Rust-based ls alternative) actually does sort this way by default, much to my delight.


shameless plug (though I don't get a cent out of this, of course): https://blog.vslira.net/2025/03/a-neat-approach-for-sortable...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: