3 ms·
This isn't a defensive response, just a genuinely curious one. For certain types of programming - generally in lower-level languages - arrays can be essential
by GrinningFool 10y ago
This isn't a defensive response, just a genuinely curious one.
For certain types of programming - generally in lower-level languages - arrays can be essential for performance. But then my assumption is that if you needed that kind of performance, you'd be using those languages.
So outside of performance, what's the functional difference between an actual array implementation - and a thing that looks, walks, and quacks like a duck?
- cutler 10y agoRuby, Python and Javascript all have native array support but can hardly be considered lower-level languages.
- asonge 10y agoJust to be clear, Javascript's arrays will, depending on the implementation, dynamically switch between sparse and compact implementations. A sparse javascript array literally behaves like a javascript object or a map with an integer index. Ruby and Python's arrays will grow as long as the allocator can alloc more memory onto the end, but has to copy the entire array if there's memory fragmentation...it's not quite the same as a C array. Because of the immutable data, your best hopes are actually vectors or maps. Btw, the erlang library you mention implements arrays on top of a tree of 10-ary(-ish) tuples. It'd need to be measured, but I'd be willing to bet that the native maps are faster at access, insert, and delete. The maps are implemented in C, and worst case for all operations would be O(n log n) or similar.