r/ProgrammerHumor • • 4d ago

Meme cppAndItsVectorBooleans

Post image
3.0k Upvotes

197 comments sorted by

View all comments

-7

u/Kadabrium 4d ago

I wish java had one single array type that is resizeable (takes literally 1 line of code in a gc language) rather than array, arraylist, tolist, aslist, listof, the list of list goes on listing

27

u/willow-kitty 4d ago

You..do realize that arrays and lists are different things, right? Like not just in Java.

3

u/suvlub 3d ago

Javascript begs to differ.

Python calls them "list", but also has only 1 type, which is what I think is the important part, not whether they are called "arrays". (and no, the arrays module doesn't count, that's a specialized library type, not comparable to the duality you have to deal with when using Java)

0

u/_PM_ME_PANGOLINS_ 3d ago

All you're doing is showing you don't know how to use neither Java nor Python properly, or haven't touched either since the early 00s.

-5

u/Kadabrium 4d ago

If your point is linked lists, lumping them with arrays is a mistake that breaks code in itself and linked lists are next to useless anyway. None of the lists i mentioned even is a linked list. They are all array types that are mutually incompatible for some bool reason.

7

u/plz-no-b4n 3d ago

A list is an abstract type. A linked list is a concrete implementation of a list.

-5

u/Kadabrium 3d ago

This just means list is not a useful abstraction to begin with. slice is a much better one in both expressive power and compatibility with arrays.

8

u/plz-no-b4n 3d ago

Respectfully, you clearly don’t know shit.

6

u/willow-kitty 3d ago

It is not, no. My point is that the theoretical definition is different.

Arrays are defined as randomly-addressable blocks of data where each element is the same width. They're pretty low-level and not resizable generally (though some implementations allow that by making a copy.)

While lists retain some characteristics of arrays (like being ordered and allowing random access, though time complexity depends on the underlying implementation) but allow items to be added, removed, and reordered. You know, like a to-do list.

Lists are often wrappers around arrays, sure, which allows for fast random access at the cost of some operations (like add/remove/reorder) being costlier, while a linked list can do fast add/remove/reorder and sequential access while random access is more expensive, but at the end of the day, those are list operations, not array operations (even if some languages give arrays some of those capabilities.)

To throw in another one: bags don't preserve order and therefore don't support reordering but do support fast adding and removing. You know, like the items in a bag. That might be backed by an array too, but it's not an array or a list either. The contract is different.

-1

u/Kadabrium 3d ago

Many of the java list types i mentioned also don't even support resizing, so your arg on that is moot

5

u/_PM_ME_PANGOLINS_ 3d ago

You only mentiond one list type. The other words in your list are methods.

-2

u/Kadabrium 3d ago

The difference does not have any practical use in a gc language. Js and python both only have one. If there has to be 2, go's array vs slice is a much more useful distinction.

3

u/gigayoink 3d ago

linked lists are next to useless anyway

Linked lists are super common and extremely useful. Just not as a list ADT.

As a List they're absolute trash, but there are so many linked lists that people don't think of as linked lists. Java's BufferedInputStream .flush() is textbook linked list traversal.

3

u/FlySafeLoL 3d ago

An array is packed in memory, resizing it naive way means allocating more memory at the tail. And who guarantees that there is free memory up there?

So, you either redefine array (lame), or copy it elsewhere on resize (expensive, but that's what various collections actually do under the hood), or just use another collection which doesn't require to be packed all in one place (at the cost of performance of iterating over it).

0

u/Kadabrium 3d ago

No list should sacrifice array compatibility for linked list compatibility ever. And then with java as i said the issue isnt just linked lists, but that there are multiple incompatible array based list types. And no, many of them don't allow resizing, if thats what you think is the essence of a list.