6 ms·
The thing is that 'return' is not very common either, because Rust has shorthand for returning at the end of a function :-P I think the standard library ought
by zozbot234 6y ago
The thing is that 'return' is not very common either, because Rust has shorthand for returning at the end of a function :-P
I think the standard library ought to use slightly longer names since it's far less strictly bounded than the set of language keywords, so I'm fine with 'Option'. 'Vec' is a bit awkward from that POV, but then again 'Vector' would be a lot worse. 'Box' is also awkward in the same way but thinking about it, it's not easy to convey the notion "this value is behind a pointer" so you might as well use a conventional name and get it over with.
- thomasahle 6y agoWhy not call it Pointer or Point?
- otachack 6y agoIn game or graphical development a Point struct/object is usually reserved for Cartesian coordinates. Pointer seems too long. C's use of "*" and "&" remain my favorite though beginners may have more difficulty understanding it, similarly to Rust's Box.
- wwright 6y agoA Box is not a pointer. It is an object with regular one-owner, no copies semantics. Semantically, it just breaks the object out so that it isn’t “internal” to whatever contains it (useful for keeping individual objects small or working around the requirement that a type have a known, finite size). A pointer and a heap allocation are the obvious choice for implementing this, but the semantics are notably different than just being a pointer. Rust also does have pointer types which represent true pointers.
- umanwizard 6y agoAFAICT, Box has exactly the same semantics as C++‘s unique_ptr.
- temac 6y agoWhere it can have the same semantics, yes. But if you look at the details, not exactly. For example Box is not nullable, but a not-nullable C++ equivalent is hard to do given the rest of the language.
- umanwizard 6y agoGood point on the nullability; yes, that is indeed different from std::unique_ptr.
- twic 6y ago> 'Vec' is a bit awkward from that POV, but then again 'Vector' would be a lot worse They should just have called it a List, and stopped the propagation of the erroneous belief that a variable-length sequence of things is a vector.
- ImprobableTruth 6y agoOr - since lists call to mind a very specific data structure (linked lists) - they could have just called it Sequence.
- remram 6y ago`List` usually refers to a linked list or similar. Vec has the important feature that it encapsulate a contiguous array, which matters in a languages like Rust.
- xscott 6y agoPython is a very popular language where the list type is implemented as an array, and named a list. Calling these things vectors (C++, Rust) is unfortunate because you eventually want real vectors for working with matrices, and the behavior is different in that context. As for linked lists, given modern processors and cache behavior, there are very few places where you ever want to chase pointers for a 1D data structure. It seems like a shame to lose a good name to a data structure that should now be avoided most of the time.