2 ms·
If you find yourself having to re-implement a sorting algorithm ad-hoc, you are probably using the wrong language. (Especially these days.)
by eru 3y ago
If you find yourself having to re-implement a sorting algorithm ad-hoc, you are probably using the wrong language. (Especially these days.)
- kstrauser 3y ago...or you're implementing a kernel and don't have full access to a libc.
- eru 3y agoWho says you have to use libc? Eg Rust has no-std crates that you can use even if you can't use the standard library.
- mort96 3y agoWhat language should they have used instead of C? And given that C's stdlib has a quicksort function, how would using a different language have helped?
- eru 3y agoBack then C might have been the best bet.
- kragen 3y agoi think it's pretty common for a specialized reimplementation of a standard library type or function to outperform it by an order of magnitude or so in some particular case. chris wellons gave an excellent example of this with hashing in golang in https://nullprogram.com/blog/2023/06/26/ https://nullprogram.com/blog/2023/06/26/ commonly (as in wellons's post about the two-sum problem) there's a variation on the standard algorithm that can help significantly, but which the standard library function doesn't have an option for also i think the cost of reimplementing simple 'algorithms from the book' like insertion sort or even quicksort is pretty low; as you saw in my comment above, insertion sort is six lines of code and only moderately bug-prone. we aren't talking about fibonacci heaps or red-black trees or fm-indexes or rader's algorithm or something. the cost is low enough that it's easy to justify in a lot of cases