News for hackers. Stuff that matters.
Re:Tour of Rust by kibwen on Sunday July 12, 2020 @05:40AM (#23810157)
The general wisdom of language/library design is that abbreviations should be used only for very common things, and only when those abbreviations are unambiguous in context. Prehistoric Rust had a rule that all keywords could be no longer than five characters (in defiance of Javascript's `function`), but forums (including HN) endlessly complained about `ret`, hence today it's `return`. :P (I admit that I wanted to Rust to change its `fn` to `func` once Swift showed its hand, but such is life.)

Meanwhile, in 2020 `Option` might be on its way to becoming a widely-accepted concept in language design, but back in 2011 it was still a radical idea that Rust was trying to smuggle over the border from functional languages, against the will of people used to languages with pervasive nullity. The language that eventually supplants Rust someday might call it `Opt` (in the same way that Rust turned C++'s `vector` into `Vec`), but back then `Option` needed all the lubrication it could get without having to get bogged down in the abbreviation bikeshedding.

Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @06:29AM (#23810353)
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.

Re:Tour of Rust by thomasahle on Sunday July 12, 2020 @07:56AM (#23810686)
Why not call it Pointer or Point?
Re:Tour of Rust by wwright on Sunday July 12, 2020 @08:27AM (#23810831)
A 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.

Re:Tour of Rust by umanwizard on Sunday July 12, 2020 @09:01AM (#23811004)
AFAICT, Box has exactly the same semantics as C++‘s unique_ptr.
Re:Tour of Rust by temac on Sunday July 12, 2020 @09:39AM (#23811206)
Where 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.
Re:Tour of Rust by umanwizard on Sunday July 12, 2020 @11:26AM (#23812043)
Good point on the nullability; yes, that is indeed different from std::unique_ptr.
Re:Tour of Rust by otachack on Sunday July 12, 2020 @08:04AM (#23810721)
In 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.
Re:Tour of Rust by twic on Sunday July 12, 2020 @10:46AM (#23811726)
> '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.

Re:Tour of Rust by remram on Sunday July 12, 2020 @10:56AM (#23811826)
`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.
Re:Tour of Rust by xscott on Sunday July 12, 2020 @01:24PM (#23812995)
Python 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.

Re:Tour of Rust by remram on Friday July 17, 2020 @01:01PM (#23872708)
An array of references. Plus, Python has no way to consume a contiguous array directly.

If you do interoperate through FFI with code in C or similar, you will have to reach for numpy arrays, which are the typed, contiguous arrays of Python.

Re:Tour of Rust by twic on Sunday July 12, 2020 @01:31PM (#23813057)
> `List` usually refers to a linked list or similar.

No, it doesn't. There are a handful of languages where this is true, and no reason other than language-specific practice to think that a list is implicitly a linked list. People always make this objection and it's honestly just bizarre.

Re:Tour of Rust by ImprobableTruth on Sunday July 12, 2020 @10:55AM (#23811824)
Or - since lists call to mind a very specific data structure (linked lists) - they could have just called it Sequence.
Re:Tour of Rust by FnuGk on Sunday July 12, 2020 @12:19PM (#23812421)
A sequence does not contain duplicates. A vector can
Re:Tour of Rust by detaro on Sunday July 12, 2020 @12:21PM (#23812440)
Mathematical sequences totally can have duplicates. E.g. to take a popular example, the Fibonacci sequence starts: 0, 1, 1, ...
Re:Tour of Rust by jcelerier on Sunday July 12, 2020 @09:54AM (#23811298)
> but back in 2011 it was still a radical idea

boost.optional was introduced in 2003

Re:Tour of Rust by qznc on Sunday July 12, 2020 @07:27AM (#23810569)
Why not `fun` as a pun?
Re:Tour of Rust by zozbot234 on Sunday July 12, 2020 @07:30AM (#23810576)
Because ML and Ocaml are already putting the `fun` in function. It would look way too derivative.
Re:Tour of Rust by techolic on Sunday July 12, 2020 @11:28AM (#23812056)
> It would look way too derivative.

Is that considered a bad thing in the Rust community?

Re:Tour of Rust by steveklabnik on Sunday July 12, 2020 @12:24PM (#23812476)
No, it is not. In fact, it is often seen as a good thing: https://steveklabnik.com/writing/the-language-strangeness-bu...
Re:Tour of Rust by timClicks on Sunday July 12, 2020 @06:33AM (#23810360)
FWIW, I really like fn.