Helping new Rustacians in 2017
17th January 2017
creativcoder / 5min
It's almost been a year and a half with Rust and it has been a productive learning experience. Coming as a newbie programmer it made me a lot more insightful and aware of what knowledge of systems programming really entails and the nuances of it, thanks to the amazing documentation, blogs and community altogether. Maintaining a good community around a language is a hard thing and Rust sets a very good example. Programming in Rust really forced me to get down into the details of compilers, llvm IR, formal systems, category theory and what not. At times the language syntax was obscure to understand and took me a time to settle in, but things fell into place. Eventually I ended up working on Servo implementing the foundations of Service Workers; meanwhile I also contributed to rustc, cargo and other rust projects. The journey has been fun :)
Rust was at top on Most loved languages of 2016 according to StackOverflow survey and there has been a growing interest among developers who want to get productive in Rust and build software systems that act reliably.
Looking forward towards 2017, Rust community has certain goals and roadmaps put forward and the very first one mentioned there is: Rust should have a lower learning curve and I think I as a programmer having a mere 2 years of real world programming experience and a year an half experience in Rust will be in a better position to highlight what areas of Rust are lacking the clarity that they deserve for a beginner.
I'll list here some of the "not so clear" topics most newcomers to Rust face. Addressing them would help progress goal #1 of the Rust roadmap 2017.
-
How to be friends with the borrow checker or fighting less with the borrow checker - This has been posted quite a few times in stackoverflow, and just recently on Reddit, which has received quite valuable advices. These explanations should really be part of the official documentation to benefit newcomers.
-
When and where to use
ref
,&
- This has also been asked by many folks over stackoverflow and other places, and it's indeed confusing initially. This post covers them very well. -
Wrapping the head around different kinds of generic trait parameters : The documentation has less coverage on how extensive, traits can be and that there can be different variants of trait impls, and I think Different Kind of Code Reuse in Rust should be the part of the official book.
-
Difficult to understand error messages - Many have expressed the fact that some of the error messages from the compiler are misleading and some use really technical words. An instance would be Issue #31174. Here, the message
non-scalar
cast for a newcomer sounds a bit technical and really could use a simple explanation. -
Concept of lvalue mutability and rvalue mutability in Rust - There are two types of mutability (lvalue and rvalue, which gives rise to different cases of statements involving the keyword
mut
:
let mut r = some_val;
let r = &mut some_val;
let mut r = &mut some_val;
and there are differences in what they mutate. Here's an article which covers those grounds.
-
Details on ordering of wrapper types : Cases like whether to use
Option<Box<T>>
or aBox<Option<T>>
in a struct field. -
Understanding the module system in Rust - A recent tweet and the accompanying blog post also mentions about it and we probably should simplify the module system of Rust. I personally feel the use of
mod
keyword redundant asuse
could do its work i guess. -
Macros use cases and various ways of using them - The little book of rust macros is indeed a great intro to them. It would be great if there was a repo containing examples of various ways macros are being used in various libraries in Rust and also when not to use them.
-
Correct ways of implementing data structures in Rust: We need more of them. Alexis's TooManyLinkedList is by far the best one in this segment and i think we probably need more. One of the most common question i hear is the proper way to implement a graph data structure in Rust. Modelling graphs in Rust covers some grounds.
-
The notion of function type implemented as traits: The
Fn
,FnMut
andFnOnce
traits and how they model the functions in Rust does not come easily to a newcomer as we usually don't see functions from a perspective of having types in other imperative languages. We should have a blog post explaining why functions are attributed to the traits they implement and what semantics does it entail for the programmer. -
Making sense of lots of lifetimes annotations and minimizing the overhead of reading Rust codebase: In order to get productive on using Rust libraries and also to be able to write some code, developers need to quickly get up to speed in understanding other Rust codebases. This comes as a blocker as there is a lot of syntax to go through regarding lifetimes and it takes time:
Lo<'a'>ts of <'a> and <'b><'c' T><U, V, X, Y>
. 😱 We would like to have a blog post explaining ways to read and understand such codebases. -
Different ways to use built in traits: Rust's Built-in Traits, the When, How & Why is a very good introduction. Also, real world use case blog posts would be benefited greatly.
-
Tagged Enums/Sum Types: Sum types are concepts mostly confined to functional languages, and people who do not have a background in functional languages may find them difficult to grasp. Understanding the notion of Sum types in Rust (i.e., the
Option
andResult
type) and the way they can encapsulate parameterized types within them. This does not come intuitively for a programmer with background from other imperative languages.
To attract more developers, we also need a drive, a reason to adopt Rust into their toolbelt. A general account and list of code examples with comparision to other languages will really help programmers appreciate the language in a greater sense. There has already been steps taken here. Code reviews like RipGrep Code Review are another ways to help people understand how language constructs are put into real world projects.
I would encourage newbie rust learners to regularly hang out in the #rust-beginners
irc channel on irc.mozilla.org
and just ask away. Rust community is encouraging, very active and eager to help out. Also do read a lot of Rust code. Thanks :)
Want to share feedback, or discuss further ideas? Feel free to leave a comment here! Please follow Rust's code of conduct. This comment thread directly maps to a discussion on GitHub, so you can also comment there if you prefer.