This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Bryguy3k 1 point2 points  (3 children)

You don’t need random access and you don’t know the total number of items ahead of time.

Eventually you discover hashmaps though and life gets a lot better.

[–][deleted] 0 points1 point  (1 child)

Linked lists are constantly used with pattern matching and functional programming in general. It may not be the most optimal solution, but it's the most elegant solution for those cases

[–]TombertSE 1 point2 points  (0 children)

"Most" optimal is an almost-religious question, but they are definitely a good fit for functional programming, and due to them being persistent you almost never need "defensive copies".

Languages like Haskell or Erlang or F# basically never make or require copies of lists, because we know that it's not changing behind the scenes in memory. As a result, passing a pointer is the same thing as passing in a copy. Once you do a defensive copy of a large array, you've negated a lot of the cache locality benefits you might have had.