Hacker News new | past | comments | ask | show | jobs | submit login
Arrays, What's the point? - Stack Overflow (stackoverflow.com)
15 points by joel_liu on Dec 26, 2008 | hide | past | favorite | 9 comments



While that may seem like a silly question, if Java and Ruby both lost the data structure entirely, my code would still function. (The frameworks it runs on, not so much.)

It is sort of like a programmer not knowing what a NAND gate is. You could get all crotchety about that, because he couldn't do a single thing without a NAND gate on his current system... but he really doesn't need to know the specifics. Many types of programming (not all, obviously) have abstracted away memory management and have pitiful speed requirements compared to the capacity of hardware (and the bottlenecks don't happen anywhere near application code), and accordingly aside from syntactic inertia there is really not that much of a reason to care about arrays any more than there is to know about your NAND gates.

(Edit: It occurs to me that I could monkeypatch Array in Ruby and replace it with an associative array and my site would probably function fine... Maybe I'll try it just to prove a point.)


It occurs to me that I could monkeypatch Array in Ruby and replace it with an associative array and my site would probably function fine... Maybe I'll try it just to prove a point.

Why bother? Just spend half an hour learning PHP, which works exactly like this. It has a data structure named "array" that is actually an associative array, and which supports both array semantics and hash semantics (and, if you're not careful, will assume one when what you want is the other).

Is this a wise design decision? Yes and no. One less data structure to think about is perhaps easier for beginners. But, as we see here, it also encourages people to remain ignorant of how their data structures actually work. If you ask yourself "would I ever use PHP to teach a data structures class", the answer would seem to be "hell, no" -- which tells you something. And when you do have to think seriously about performance (which, though it often happens too soon, does have to happen eventually) it seems to me that you'd want an array primitive in your toolkit. (At that point, hardcore PHP developers would probably advocate just dropping into C and writing C extensions.)


But if you turned all your ArrayLists into LinkedLists, what would happen to the performance of your programs?


The 1 millisecond of application logic between the 150 millisecond roundtrip to the database and 800 millisecond network latency would be 3 milliseconds?


I'm worried that (according to his stackoverflow profile) a 'Long-time Informix user and developer, experienced in C and Unix (many variants)' asks such a question.

I mean, seriously?


As mentioned in the Reddit comments on this, a stackoverflow question can be edited, and if it is, the most recent editor shows up in the bit you've looked at. And that is this person, who isn't the original questioner.


You've looked at the profile of the last editor of the question but the original author is Xesaniel http://stackoverflow.com/users/48214/xesaniel


there is also a berkeley CS class youtube video that goes into the differences between a linked list and an array:

http://www.youtube.com/watch?v=Wp8oiO_CZZE

it is a good intro to the subject, however, Shewchuk does not thoroughly explain the difference beetween lookup/ access time and search time for arrays and linked lists. I like the explanation given by the commenter on stackoverflow


I would find it very odd if this guy didn't know what an array was but did know what a linked list is.

I'm guessing (since I've been there myself at one point) that he thinks a list is just some list in memory and he doesn't understand the internal representation of any of the structures at all.




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

Search: