about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLemmingAvalanche <haugsbakk@yahoo.no>2014-07-04 13:19:42 +0200
committerLemmingAvalanche <haugsbakk@yahoo.no>2014-08-10 22:51:22 +0200
commit14e245bd47d3ac1a981d50a6f752aa27cca7d85e (patch)
tree481feb6a95bad684ca0fb53431d5a48048b8b5b3
parent5012b858ed939ced9e4ac6c7a31c0a038661dd92 (diff)
downloadrust-14e245bd47d3ac1a981d50a6f752aa27cca7d85e.tar.gz
rust-14e245bd47d3ac1a981d50a6f752aa27cca7d85e.zip
Note naming convention of lists (xs, ys, ...)
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.

I assumed that the convention came from a language like Haskell, so I
tailored the explanation according to that.
-rw-r--r--src/doc/tutorial.md10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md
index 2a788d7e793..96b57f59cce 100644
--- a/src/doc/tutorial.md
+++ b/src/doc/tutorial.md
@@ -1110,6 +1110,16 @@ let xs = Cons(1, box Cons(2, box Cons(3, box Nil)));
 let ys = xs; // copies `Cons(u32, pointer)` shallowly
 ~~~
 
+> *Note:* Names like `xs` and `ys` are a naming
+> convention for collection-like data structures
+> (like our `List`). These collections are given 
+> names appended with 's' to signify plurality, 
+> i.e. that the data structure stores multiple 
+> elements.  For example, `xs` in this case can 
+> be read as "a list of ex-es", where "x" here 
+> are elements of type `u32`.
+
+
 Rust will consider a shallow copy of a type with a destructor like `List` to
 *move ownership* of the value. After a value has been moved, the source
 location cannot be used unless it is reinitialized.