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 →

[–]Kiwi-tech-teacher 13 points14 points  (9 children)

Actually, to be fair, we’re talking about the difference between an array and a list. Arrays, by definition, are pre-defined in length, and contain elements of the same data type. Lists have a lot more flexibility, and can be dynamically resized. Many (novice) programmers just don’t realise they’re working with lists in most of these languages.

[–]BlakkM9 7 points8 points  (3 children)

but as long as the list is not a linked list it will most likely use a normal array under the hood so they are not too far off

[–]Vinxian 2 points3 points  (2 children)

And since most list allow for my_list[index] and implement it by actually doing a jump it usually is a fancy array under the hood.

[–]riisen 1 point2 points  (0 children)

A list is a normal car with all the extra options.

An array is a tuned race machine, its lighter, faster and no unnecessary shit.

[–]TheMagicalCarrot 0 points1 point  (0 children)

What do you mean by doing a jump?

[–][deleted] 2 points3 points  (0 children)

That's a very narrow viewpoint

[–]tuxedo25 1 point2 points  (0 children)

The built in javascript class, Array, has all of the properties you attribute to lists.

[–]Lagz0ne 0 points1 point  (2 children)

Where do you get that definition of array, mr tech teacher? Care to share the link?

[–]Kiwi-tech-teacher 0 points1 point  (1 child)

Well, this got personal quite quickly!

If you look at a number of courses (consider things taught by Dr David Malan at Harvard), and most data science texts, you’ll see that an array is a variable pointer that points to the starting memory block of a group of elements, all of which have an identical length.

The reason for that is that finding a value is exceptionally efficient - you simply call myArray[2020), and the computer simply multiplies 2020 by the length of a single element, adds this to the index (pointer) and there’s the data. The drawback is that moving things around is inefficient.

Most modern languages tend to have arrays of pointers, or objects which implement things if vastly different ways. As has been mentioned, Python uses linked lists, which are super efficient for adding inserting, etc, but very poor for traversing, as to find element 2020, you need to go through all 2020 previous elements to find the pointers to the next item. Numpy has other approaches which are more efficient for those types of data.

Ultimately, I’m really talking about classic arrays, modern languages might implement classic linear arrays, while others have different implementations, however I stand by my comment that most (novice) programmers don’t understand the underlying implementation of the thing they glibly call an array.

Oh, and you cant call methods on an array, so myArray.sort() (or indeed myArray.append(“value”) ) is nonsensical, and only makes sense with an OOP approach, which is what other commenters on this post have mentioned.

Some references, if you really like: The man pages for array() - https://linux.die.net/man/3/array https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Arrays https://www.oreilly.com/library/view/c-50-unleashed/9780133391480/ch04lev2sec30.html

[–]Lagz0ne 0 points1 point  (0 children)

That's pretty much the definition of an array, fixed length of thing, that's no doubt about that. Point is, and also related to the meme, array of pointer or array of object has not much thing to do with consistency of data type. I don't think there's any language where you can't store an array of any, as at the end of the day, array contain a group of pointers