Skip to content

Commit 4d27b48

Browse files
committed
auto merge of #15410 : LemmingAvalanche/rust/patch-1, r=alexcrichton
People reading the tutorial may not be familiar with the convention of naming lists, vectors and the like as xs, ys, etc. Without some explanation of the reasoning behind it, it might come off as just throwaway non-descriptive names. Languages like Haskell gets flak from using short, non-descriptive names, while in reality, there are clear conventions and reasons for using certain terse variable names. This is just a proposed explanation of this convention, as I've interpreted it - I assumed that the convention came from a language like Haskell, so I tailored it according to that. So beware that I might have misjudged how it is used in the Rust language, or at least how it is used in the Rust tutorial.
2 parents c4a63fa + 14e245b commit 4d27b48

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/doc/tutorial.md

+10
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,16 @@ let xs = Cons(1, box Cons(2, box Cons(3, box Nil)));
11331133
let ys = xs; // copies `Cons(u32, pointer)` shallowly
11341134
~~~
11351135

1136+
> *Note:* Names like `xs` and `ys` are a naming
1137+
> convention for collection-like data structures
1138+
> (like our `List`). These collections are given
1139+
> names appended with 's' to signify plurality,
1140+
> i.e. that the data structure stores multiple
1141+
> elements. For example, `xs` in this case can
1142+
> be read as "a list of ex-es", where "x" here
1143+
> are elements of type `u32`.
1144+
1145+
11361146
Rust will consider a shallow copy of a type with a destructor like `List` to
11371147
*move ownership* of the value. After a value has been moved, the source
11381148
location cannot be used unless it is reinitialized.

0 commit comments

Comments
 (0)