4 ms·
I use lists a lot. That's because I program in Lisp most of the time. Lists are a very flexible data structure. But I wouldn't use them in a language if I
by DonaldFisk 10y ago
I use lists a lot. That's because I program in Lisp most of the time. Lists are a very flexible data structure. But I wouldn't use them in a language if I had to implement them from scratch, such as C, or in a language where the functional style is unnatural, such as Java or Python, even though both those languages have basic support for them. I'd use vectors and hash tables instead. They're less flexible than lists, but good enough for most purposes (and they might even be faster).
The only time I can remember implementing lists is when writing a Lisp interpreter or virtual machine. And that uses a fixed length array of cons cells, so no dynamic heap allocation is necessary.
I've been asked list-related questions at interviews several times, e.g. how to destructively reverse one, and how to tell if a list is circular. If it's just to check that I really have implemented Lisp, then they're reasonable questions, but I suspect all the candidates for the same job were asked those questions.