11 ms·
It's std::vector that was weirdly named. In plenty of codebases "Vector", particularly gamedev and scientific, will mean the mathematical object with that name.
by yakubin 4y ago
It's std::vector that was weirdly named. In plenty of codebases "Vector", particularly gamedev and scientific, will mean the mathematical object with that name.
Other languages don't need to replicate this mistake.
- dleslie 4y agoAnd yet it is the name used in C++ code for a variable length container of contiguously stored data.
- marssaxman 4y agoThis is intended to be a different language, is it not?
- dleslie 4y agoNot wholly different; it appears to be intended to interop with, and progressively replace C++ in existing projects.
- deleted 4y ago[deleted]
- cnity 4y agoTrue, though in OP's defense I don't know if I've ever seen a language refer to a growing list of entries as an "array".
- linkdd 4y agoWell, the data structure is called a dynamic array
- cnity 4y agoI don't see any reference to it in the GH readme, but I do wonder what they call actual arrays (as in, fixed size allocations of memory that store a contiguously typed value).
- linkdd 4y agoI was talking about std::vector (and Rust's Vec). Those are dynamic arrays (as in, growable allocations of memory that store a contiguously typed value).
- yakubin 4y agoJava: ArrayList Zig: ArrayList GLib: GArray Objective-C: NSMutableArray
- domenukk 4y agoFWIW, ArrayList is a List, backed by Arrays. So List would have been the more Java/Zig way to name it (also Python, etc.)
- yakubin 4y ago> FWIW, ArrayList is a List, backed by Arrays. You probably know that, but just to clarify: it's backed by a single array, reallocated repeatedly, just like std::vector in C++ (although growth factors are different, I think). Just "List" probably risks that some people will jump to the conclusion that it's a linked list. I'd probably prefer the full "ArrayList". Although personally I'd use something like "DynArray"/"DynamicArray".
- cnity 4y agoThese are examples in favor of my point, not against it.
- jsnell 4y agoDoesn't seem particularly uncommon. Perl, JavaScript, and Ruby come to mind if you're really looking for languages that use just a raw term "array" with no extra qualifiers.
- slt2021 4y agoObject Pascal's arrays are dynamic. var kek: array of int; setlength(kek, 666); // kek is now int[666] setlength(kek, 1337); // kek is now int[1337]
- kllrnohj 4y agoJava's Vector looks around awkwardly, hoping everyone forgets it existed... ;)
- yakubin 4y agoActually, I've never known it existed. You're the one who reminded me now. :)
- CuriousCosmic 4y agoWith the new versions of the JDK I think they will. The Java Vector features will be out of incubator in the next year or so and unlike the existing Vector, it's actually useful. For context the new vector features are for SIMD support on the JVM.
- kllrnohj 4y agoI'm honestly surprised java.util.Vector still exists. It was "deprecated" in 1.2 or something like that? I guess there's no pressure to actually remove it, though. I only know about it from dealing with J2ME crap where ArrayList wasn't available.
- int_19h 4y agoJava doesn't remove things from the standard library. AWT is still around, too.
- fluoridation 4y agoAn std::vector is a vector in the mathematical sense, though. It's a homogeneous tuple. It's just that using an std::vector of std::vectors to store a list of points would be inefficient.
- xigoi 4y agoA vector can't change its size or contain things that aren't elements of a field. A std::vector can.
- fluoridation 4y agoYes, you can have a vector of, say, naturals. I'm pretty sure you can even create a vector field out of vectors of non-reals.
- Koshkin 4y agoA "vector field" and a "field" are two completely different notions. (And yes, you can build a field from integers.) https://en.wikipedia.org/wiki/Finite_field https://en.wikipedia.org/wiki/Finite_field
- fluoridation 4y agoMy bad. I meant to say "vector space", not "vector field". I understand the difference, but I often make this mistake because the set of a vector space is almost always the set of an algebraic field (i.e. the reals).
- xigoi 4y agoReally? What is the additive inverse of (1, 2, 3) ∈ ℕ³ ?
- fluoridation 4y agoIt depends on how you define addition.