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

Even if the disk sorts directory entries by file name and you want to show them sorted by file name, chances are you have to sort.

Reasons? Firstly, you’d have to know the entries are sorted. For that, you need an API that tells you that or hard-code information about file systems in your code. They may exist, but I’m not aware of any file system API that provides that information.

Secondly, the file system may not return the names sorted in the locale you want to sort them in.

Thirdly, the sorting code used in the file system may contain a bug. Once file systems are out there, you can’t fix them (happened in one of Apple’s file systems. HFS, IIRC)

Lastly, modern GUIs tend to sort file names containing numbers non-alphabetically, so that, for example “file 2.jpg” gets sorted before “file 12.jpg”.

So, I think it’s easier to always sort. I would pick an algorithm that works well when items are mostly sorted at the start, though.



you have indexes............




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

Search: