Archived [rant] Somethings you'll learn in college but should NEVER use in the real world (programming)
submitted ago by lmkevin
Posted by: lmkevin
Posting time: 3.9 years ago on
Last edit time: never edited.
Archived on: 4/24/2017 10:00:00 AM
Views: 631
SCP: 7
9 upvotes, 2 downvotes (82% upvoted it)
Archived [rant] Somethings you'll learn in college but should NEVER use in the real world (programming)
submitted ago by lmkevin
view the rest of the comments →
[–] Phen 0 points 7 points 7 points (+7|-0) ago
Linked lists have O(1) random insertion (if you're already at your link node), array lists do not. Array-based lists have O(1) random access, linked lists do not. The correct choice depends on the workload.
Nearly all lists I work with on a day-to-day basis are just collections to be iterated over for some sort of processing like validation or whatever. Algorithmically, either would be fine. Array lists have a lower memory overhead, so it's reasonable that they should be chosen for most cases, especially if you have a good idea of the buffer size.
But they certainly should not be chosen for ALL workloads.
For example, the application I write at work maintains a navigation stack. Depending on user action, we may need to remove the head or tail of the stack, pop or push navigation states. If the user navigates to a screen, we push the screen on the top of the stack and pop the tail so that we don't keep too much history. As the user goes back and forward, the list node moves to previous or next. Etc. How is that stack implemented? A linked list, of course! Anything else would be silly. It could have be implemented as an array list, after all the number of elements is so small that there would be no measurable performance impact. But we'd just have to write an interface overtop of the array-based list that looks the same as what the linked list already provides, so why bother?
HOWEVER, I think all of that misses the point of education entirely. Even if the linked list isn't used all over the place, you still need to understand the algorithms! That's the point of education. A college education in programming shouldn't just be bunch trade school style instructional courses where you're told what to do and how to do it. You have to understand the abstract data structures, why they're used, why they behave as they do, why you should use them, why you should avoid them.
If you don't, you'll risk winding up like my coworker who uses linear lookups for everything even when hashtables are the obvious solution. (Curse you LINQ!)