course_rust_vocational_training.md 15.8 KB
Newer Older
1
<h1 id="page-title">Rust Vocational Training</h1>
Dario Pinto's avatar
Dario Pinto committed
2
<br/>
3

Dario Pinto's avatar
Dario Pinto committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<div class="row">
  <div class="col-lg-6">
    <ul class="list-group list-group-flush">
      <li class="list-group-item">Length: from 1,5 to 5 Days</li>
      <li class="list-group-item">Pricing for modules(tax NI): 1-2 = 1990€/person and 1-3 = 2490€/person </li>
      <li class="list-group-item">Attendees: developpers</li>
      <li class="list-group-item">Available remotely: yes</li>
      <li class="list-group-item">Tutors: <a class="navlink" href="team">Adrien Champion</a></li>
    </ul>
  </div>
  <div class="col-lg-6">
    <h4>Make it happen!</h4>
    <br />
    <div class="col-lg-12" align="center">
      <div class="list-group">
        <a class="list-group-item list-group-item-action list-group-item-dark" href="mailto:contact@ocamlpro">Next sessions!</a>
        <a class="list-group-item list-group-item-action list-group-item-dark" href="mailto:contact@ocamlpro">Contact us!</a>
      </div>
    </div>
  </div>
</div>
25

Dario Pinto's avatar
Dario Pinto committed
26
<hr class="featurette-divider">
27

Dario Pinto's avatar
Dario Pinto committed
28
<h2 class="page-subtitle">Overview</h2>
29

Dario Pinto's avatar
Dario Pinto committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
Rust is a language with C/C++-like performance with very expressive, **zero-cost** abstraction mechanisms from functional programming languages; it also generates the memory allocation strategy of the program automatically if one exists, and, if none do, can point precisely to what the problem is. It it also worth noting that Rust has an extremely ergonomic and powerful project/package manager, [cargo](https://doc.rust-lang.org/stable/cargo/), and shines in the quality of the explanation and suggestions that come with its compiler errors. It is thus not surprising that Rust is so popular: it has been voted “most loved programming language” in the [StackOverflow developer survey](https://insights.stackoverflow.com/survey/2019#most-loved-dreaded-and-wanted) for four years in a row, and has an impressive number of [companies running it in production](https://prev.rust-lang.org/en-US/friends.html) for a young systems language.

<br/>

<div class="row">
  <div class="col-lg-6">
    <h3>Objectives</h3>
    <ul>
      <li>
        Master the main principles of Rust: ownership and traits
      </li>
      <li>
        Master the ecosystem: project management, dependencies, sub-project layout
      </li>
      <li>
        Master declarative macros
      </li>
      <li>
        Getting acquainted with standard and extended libraries in a pratical environment
      </li>
      <li>
        Using bound advanced polymorphism: higher-kinded types and associated types
      </li>
      <li>
        Manage concurring parts of a programme, understanding the safety guarantees the Rust offers in that context
      </li>
      <li>
        Some introduction to <strong>Unsafe Rust</strong>
      </li>
    </ul>
  </div>
  <div class="col-lg-6">
    <h3>Prerequisites</h3>
      To do the complete course:
      <li>
        Being familiar with another programming language
      </li>
      <li>
        Being able to develop in a function language, being familiar with pattern-matching, strong type systems, algebraic types, polymorphism....
      </li>
      To access confirmed and advanced sessions:
      <li>
        Basics in project management
      </li>
      <li>
        Basic understanding of the concept of ownership in Rust
      </li>
      <li>
        Being able to write small programs that use certain run-of-the-mill aspects of the standard library. Including the following: <code>Option</code> and <code>Result</code> types, and simple traits like <code>Write</code>, <code>Read</code>, <code>Display</code>, <code>From</code>, <code>Into</code>... 
      </li>
  </div>
</div>

<hr class="featurette-divider">

<div class="row">
  <h2 class="page-subtitle">Modules</h2>
  <div class="col-lg-4">
    <h4>Introduction</h4>
    <p><strong>Module 1 (1,5 days)</strong></p>
    <p><strong>Basics : </strong>types and expressions,functions, using macros, user-defined types, loops and panic mode...</p>
    <p><strong>Ecosystem : </strong>manage a simplistic project, dependencies, organising modules, <code>rustfmt</code>...</p>
    <p><strong>Traits : </strong>simple polymorphism, define and implement traits...</p>
    <p><strong>Ownership : </strong>semantics of copy and move, refenrences and lifetimes, slice types...</p>
  </div>
  <div class="col-lg-4">
    <h4>Rust in the real World</h4>
    <p><strong>Module 2 (2 days)</strong></p>
    <p><strong>Macros : </strong>define declarative macros, handle visibility...</p>
    <p><strong>Traits : </strong>rules, extensibility, associated types, constraints of advanced polymorphism...</p><p><strong>Ownership and memory : </strong>lifetimes, boxing, <code>Copy</code> and <code>Clone</code>, advanced traits...</p>
    <p><strong>Ecosystem : </strong>meta-attributes, documentation, tests, managing mid to large projects...</p>
    <p><strong>Main standard and extended libraries (<a href="http://www.crates.io">crates.io</a>):</strong> iterators and records, error handling, “fearless concurrency” on iterators...</p>
    <p><strong>Complex use case :</strong> incapsulates virtually every concept presented in the course in a fairly complex project.</p>
  </div>
  <div class="col-lg-4">
    <h4>Advanced features</h4>
    <p><strong>Module 3 (1,5 days)</strong></p>
    <p><strong>Fearless concurrency :</strong> threads and traits like <code>Send</code> and <code>Sync</code>, <code>mpsc</code>, locks...</p>
    <p><strong>Advanced traits : </strong>higher-kinded types, object traits (dynamic dispatch), function pointers...</p>
    <p><strong>Writing and using procedural macros</strong></p>
    <p><strong>Discovering <em>unsafe Rust</em></strong></p>
    <p><strong>Complex use case :</strong> plain and complete introduction to &#8220;fearless concurrency&#8221; and &#8220;advances traits&#8221;</p>
  </div>
</div>

  <br/>
  <p align="center"><strong>This course is modular! Participants may attend the entire session, or just modules 1 and 2, or module 2 alone, or stick to modules 2 and 3.</strong></p>

<hr class="featurette-divider">

<h2 class="page-subtile">Pricing</h2>

All costs given below are for open sessions. Pricing for exclusive sessions depends on the number of participants and the actual location, <a href="mailto:contact@ocamlpro.com">contact us</a> for an estimation.

<div class="row">
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}
.tg .tg-7btt{border-color:inherit;font-weight:bold;text-align:center;vertical-align:top}
</style>
<table class="tg">
<thead>
  <tr>
    <th class="tg-7btt">Full Session</th>
    <th class="tg-7btt">Beginner</th>
    <th class="tg-7btt">Intermediate</th>
    <th class="tg-7btt">Beginner and Intermediate</th>
    <th class="tg-7btt">Intermediate and advanced</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-c3ow">3,500.00€</td>
    <td class="tg-c3ow">1,500.00€</td>
    <td class="tg-c3ow">2,000.00€</td>
    <td class="tg-c3ow">3,000.00€</td>
    <td class="tg-c3ow">3,000.00€</td>
  </tr>
  <tr>
    <td class="tg-c3ow">4 days</td>
    <td class="tg-c3ow">1 day</td>
    <td class="tg-c3ow">2 days</td>
    <td class="tg-c3ow">3 days</td>
    <td class="tg-c3ow">3 days</td>
  </tr>
</tbody>
</table>
</div>
162

Dario Pinto's avatar
Dario Pinto committed
163
<hr class="featurette-divider">
164 165

<h2 class="page-subtitle">Layout</h2>
Dario Pinto's avatar
Dario Pinto committed
166 167 168 169 170 171 172 173 174
<div class="row">
  <div class="col-lg-4">
  <br/>
  The session is divided in three parts:

  1. A beginner introduction to Rust’s basics features (one day);
  2. Crucial features and libraries for real-life development, along with a complex use-case used to showcase how to use them in a real project (two days);
  3. Advanced/specific features (one day).
  </div>
175

Dario Pinto's avatar
Dario Pinto committed
176 177 178
  <div class="col-lg-4"> 
    Note that attendees planning to start at part 2 must make sure they are comfortable with the topics of part 1. This means, roughly, basic project management, having a basic understanding of ownership, and being able to write small programs that use some of the most common features of the standard library. Typically, this includes types Option, Result… and “simple” traits such as `Write`, `Read`, `Display`, `From`, `Into`...
  </div>
179

Dario Pinto's avatar
Dario Pinto committed
180 181 182 183
  <div class="col-lg-4">
    The road map below details the topics discussed in each part. Participants can chose to attend either the whole session, parts 1 through 3, parts 1 and 2, only part 2, or parts 2 and 3.
  </div>
</div>
184 185


Dario Pinto's avatar
Dario Pinto committed
186 187
<hr class="featurette-divider">

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215

<h2 class="page-subtitle">Road Map</h2>

1. **Day 1: Introduction**
    * basics: types and expressions, functions, using macros, user-defined types, loops, panic…
    * ecosystem: basic project management, dependencies, modules organization, rustfmt…
    * traits: simple polymorphism, defining and implementing traits…
    * ownership: copy/move semantics, references and basic lifetimes, slices…
2. **Days 2 and 3: Real-life Rust**
    * macros: defining declarative macros, handling visibility…
    * traits: rules, extensibility, associated types, advanced polymorphism constraints…
    * ownership and memory: lifetimes, boxing, Copy and Clone, higher-order traits…
    * ecosystem: meta-attributes, documentation, testing, anatomy of medium to big projects…
    * must-know standard and extended (crates.io) libraries: iterators and collections, error-handling, simple but fearless concurrency over iterators…
    * complex use-case: showcase virtually all topics discussed so far on a (relatively) complex
    project (roughly 2~3kloc)
3. **Day 4 : advanced features**
    * fearless concurrency: threads, the Send and Sync traits, mpsc, locks…
    * advanced traits: higher-kinded types, trait objects (dynamic dispatch), function pointers…
    * writing and using procedural macros
    * (relatively) shallow dive in unsafe Rust
    * complex use-case: showcase “fearless concurrency” and “advanced traits” topics on the complex use-case from days 2-3

> **NB:** while the different parts of the session are presented in chronological order, the topics inside each parts only loosely represent the actual order in which they will be discussed.

Part 3 discusses relatively specific topics, in particular unsafe Rust and procedural macros. This is where the training has the most flexibility and can be customized depending on the participants.
For instance, it is possible to replace the discussion on procedural macros and/or unsafe Rust by a deeper dive into fearless concurrency and/or an exercise session where attendees can practice the notions seen so far (typically from part 2) while the trainer provides hints, help and insights when needed.

Dario Pinto's avatar
Dario Pinto committed
216 217
<hr class="featurette-divider">

218 219 220 221 222 223 224 225 226 227
<h2 class="page-subtitle">Open and Exclusive Sessions</h2>

So called “open sessions” are training sessions organized and hosted by OCamlPro in Paris, close to the Alésia metro station (line 4). These sessions are presented in French, although the slides are
in English. Open sessions do not provide any flexibility regarding part 3, except if **all** attendees agree on some modifications. For instance, trading the discussion on procedural macros for supervised exercises.

“Exclusive sessions” are training sessions given exclusively to a single company. These sessions can be hosted by OCamlPro or the company, although the latter depends on where the company is actually located. Compared to open ones, exclusive sessions let the company chose

   1. The language used during the session, between French and English (note that the slides themselves will be in English regardless), and
   2. Most aspects of part 3 (the last day).

Dario Pinto's avatar
Dario Pinto committed
228 229
<hr class="featurette-divider">

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
<h2 class="page-subtitle">Workflow and Preparation</h2>

The whole session will rely heavily on examples. Attendees willing to follow along / experiment with the examples on their own machine during the session are encouraged to do so but should make sure they install Rust and setup a text editor or IDE appropriately.

Installing Rust is fairly easy on any mainstream operating system, see [rustup](https://www.rust-lang.org/tools/install) for more details. Do
note that installing Rust using a package manager is not recommended: Rust has a relatively fast release cycle that does not mix well with the inertia of most package managers. Ideally, one should always use the latest version, and attendees should make sure their Rust toolchain is up to date. Unless they do not plan to write code at all.

Mainstream text editors and IDEs have Rust syntax highlighting either built-in or available as a
plugin. Beware that code completion is currently a bit difficult to add to some text editors.
IntelliJ-based IDEs usually support code completion perfectly thanks to the [Rust IntelliJ plugin](https://intellij-rust.github.io/).

It is also worth noting that Rust has a very nice [online playground](https://play.rust-lang.org/) where one can write, build and run small programs. It constitutes a nice, hassle-free way to experiment with small examples without installing anything. Beware that attendees relying solely on the online playground will not be able to build, run or experiment with the complex use-case used in the session to showcase Rust features in the real world. This requires a local installation of the toolchain.

The trainer will use a terminal to run most commands and Sublime Text 3 (without code completion, but with error integration) to show and edit code during the session.

> **NB:** attendees to the open sessions will be provided free wifi, although we can give no guarantee in terms of bandwidth. Again, attendees should make sure to have their environment setup beforehand to avoid last minute issues impacting the session, bandwidth-related or otherwise.

Dario Pinto's avatar
Dario Pinto committed
247
<hr class="featurette-divider">
248

Dario Pinto's avatar
Dario Pinto committed
249
<h2 class="page-subtitle">What is Rust?</h2>
250

Dario Pinto's avatar
Dario Pinto committed
251 252 253 254 255 256 257
[Rust](https://www.rust-lang.org/) is a systems language with a strong focus on safety, efficiency and (safe) concurrency. Its development is spearheaded by Mozilla, although the vast majority of contributions to Rust come from external developers since Rust and its ecosystem are developed in the open.

Rust borrows heavily from functional programming languages to provide very expressive abstraction mechanisms. Because it is a systems language, these mechanisms are almost always zero-cost. For instance, polymorphic code has no runtime cost compared to a monomorphic version.

This concern for efficiency also means that Rust lets developers keep a very high level of control and freedom for optimizations. Rust has no Garbage Collection or any form of runtime memory inspection to decide when to free, allocate or re-use memory. But because manual memory management is almost universally regarded as dangerous, or at least very difficult to maintain, the Rust compiler has a borrow-checker which is responsible for i) proving that the input program is memory-safe (and thread-safe), and ii) generating a safe and “optimal” allocation/deallocation strategy. All of this is done **at compile-time.**

While ownership, the underlying principle of the borrow-checker, is often quite daunting for newcomers, Rust integrates this approach to memory management very nicely in the language. Huge efforts have been deployed to make this mechanism as natural as possible. In fact, most seasoned Rust developers internalize the borrow-checker and seldom actually think about it. For such developers, the borrow-checker is not a constraint: it only rejects programs because of typos, “minor oversights”, or (very rare) deep architectural errors from the developer. Meaning, the borrow-checker rejects memory-unsafe programs. (The same, to some extent, can be said about thread-unsafe programs.)