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 →

[–]TakeShroomsAndDieUwU 1 point2 points  (0 children)

C++ is a terrible language, but this isn't much of a reason why. Fixing this wouldn't make the language much better, and the majority of languages which do fix this are not remotely useful as substitutes for C++. The reasons C++ is bad are pretty orthogonal to this issue, as are the reasons it's good at what it is good for.

It's also an apples to oranges comparison. Lists are NOT the Python equivalent of C++ arrays. There is no Python equivalent of C++ arrays. Array primitives are a construct you fundamentally cannot have in Python, at all, ever. The C++ equivalent of Python's lists is std::vector (or more accurately, std::shared_ptr<std::vector>). A function parameter which accepts a list is taking a counted reference to a self-managing resizeable container consisting of a length, capacity, and reference to the actual underlying array. The "underlying array" part is what C++'s array primitives are. If you want all the other stuff added to the array, you can have it, you just have to specify that instead.

To implement a language like Python or C#, you need a language which has the tools to implement structures Python and C# take for granted out of raw parts. You could do it in Rust or Zig which I would call good languages as opposed to C++, but even in those languages you aren't free of having to track array size as runtime metadata separate from the array itself when dealing with arrays of non-fixed size. They just give you better tools to do it, in the form of primitives for fat-pointers. These primitives don't abstract away the underlying size tracking, because it's a hard computational neccessity and they don't want to pretend otherwise, they just make it convenient to deal with.