My presentations, using Reveal.js (mostly in Portuguese).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

612 lines
19 KiB

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Por que você deveria aprender Rust</title>
<meta name="description" content="Por que você deveria aprender Rust">
<meta name="author" content="Julio Biason">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<link rel="stylesheet" href="reveal.js/css/theme/night.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
<style type="text/css" media="screen">
.happy {
color: yellow;
}
.reveal section img {
border: none;
}
.reveal ul.empty {
list-style: none outside;
}
li {
display: block;
}
.cursor {
background-color: #666;
color: white;
}
img {
max-height: 90%;
}
td.seen {
font-style: italic;
font-weight: bold;
}
.semi-opaque {
background-color: rgba(0, 0, 0, 0.7);
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section data-background="_images/rust-ferris.png" data-header>
<h1 class="semi-opaque">Por Que Rust</h1>
</section>
</section>
<section>
<section>
<img src="_images/avatar-20170726.png" alt="Me" style="float:left;width:200px;" class="no-border">
<div>
<ul class="empty">
<li>Júlio Biason</li>
<li>https://functional.cafe/@juliobiason</li>
<li>julio.biason@pm.me</li>
<li><a href="http://presentations.juliobiason.net">http://presentations.juliobiason.net</a></li>
</ul>
</div>
</section>
</section>
<section>
<section>
<p>
<a href="https://insights.stackoverflow.com/survey/2019">
A languagem mais amada segundo o StackOverflow
Survey 2019
</a>
<p class="fragment">... pelo 4⁰ ano seguido.</p>
</p>
</section>
</section>
<section>
<section>
<h2>Imutabilidade por Default</h2>
</section>
<section>
<pre><code class="hljs rust" data-trim>
fn main() {
let a = 2;
a = 3;
println!("{}", a);
}
</code></pre>
</section>
<section>
<pre><code class="hljs" data-trim>
3 | let a = 2;
| -
| |
| first assignment to `a`
| help: make this binding mutable: `mut a`
4 | a = 3;
| ^^^^^ cannot assign twice to immutable variable
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
fn main() {
let mut a = 2;
a = 3;
println!("{}", a);
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>Borrow Checker</h2>
</section>
<section>
<pre><code class="hljs rust" data-trim>
a = String::from("hello");
</code></pre>
</section>
<section>
"Variável <code>a</code> tem o valor <code>"hello"</code>"
</section>
<section>
<div>
"Posição de memória apontada por <code>a</code> tem o valor <code>"hello"</code>"
</div>
<div class="fragment">
<pre><code>
0x3f5cbf89 = "hello"
</code></pre>
</div>
<img src="_images/rust-memory.png" alt="" class="fragment">
</section>
<section>
<div>
A language that doesn't affect the way you think
about programming, is not worth knowing.
</div>
<div>
-- Alan Perlis, "ALGOL"
</div>
</section>
<section>
<pre><code class="hljs rust" data-trim>
fn main() {
let a = String::from("hello");
let _b = a;
println!("{}", a)
}
</code></pre>
</section>
<section>
<pre><code>
error[E0382]: borrow of moved value: `a`
--> src/main.rs:5:20
|
4 | let _b = a;
| - value moved here
5 | println!("{}", a)
| ^ value borrowed here after move
|
= note: move occurs because `a` has type `std::string::String`, which does not implement the `Copy` trait
</code></pre>
</section>
<section>
<p>E se eu precisar acessar a variável em mais de um lugar?</p>
<h3 class="fragment">References</h3>
</section>
<section>
<pre><code class="hljs rust" data-trim>
fn main() {
let a = String::from("hello");
let _b = &a;
println!("{}", a)
}
</code></pre>
</section>
<section>
<img src="_images/rust-reference.png" alt="">
</section>
<section>
<h3>Regras do Borrow Checker</h3>
<p class="fragment">
Uma região de memória tem apenas um dono.
</p>
<p class="fragment">
A região é desalocada quando o dono sair de escopo.
</p>
</section>
<section>
<h3>Regras do Borrow Checker</h3>
<p class="fragment">
Uma região de memória pode ter inifitas referências.
</p>
<p class="fragment">
... desde que elas não durem mais do que o dono.
</p>
</section>
<section>
<h3>Regras do Borrow Checker</h3>
<p class="fragment">
É possível ter uma referência mutável de uma região de memória.
</p>
<p class="fragment">
... mas para haver uma referência mutável ela deve ser
a <strong>única</strong> referência.
</p>
</section>
<section>
<img src="_images/dunno.jpg" alt="">
</section>
<section>
<pre><code class="hljs go" data-trim>presente := Presente { ... }
canal &lt;- presente</code></pre>
</section>
<section>
<pre><code class="hljs go" data-trim>presente := Presente { ... }
canal &lt;- presente
presente.abrir()</code></pre>
</section>
<section>
<a href="https://swift.org/blog/swift-5-exclusivity/">Swift 5 Exclusivity Enforcement</a>
</section>
</section>
<section>
<section>
<h2>Tipos Algébricos</h2>
<p class="fragment">(structs)</p>
</section>
<section>
<h3>struct</h3>
<pre><code class="hljs rust" data-trim>
struct Present {
package_color: String,
content: String
}
</code></pre>
</section>
<section>
<h3>enum</h3>
<pre><code class="hljs rust" data-trim>
enum IpAddr {
V4,
V6
}
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
enum IpAddr {
V4(String),
V6(String),
}
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
let home = IpAddr::V4(String::from("127.0.0.1");
match home {
V4(address) =&gt; println!("IPv4 addr: {}", address),
V6(address) =&gt; println!("Ipv6 addr: {}", address),
}
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
enum Option&lt;T&gt; {
Some(T),
None
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>Error Control</h2>
</section>
<section>
<pre><code class="hljs python" data-trim>
try:
something()
except Exception:
pass
</code></pre>
</section>
<section>
<pre><code class="hljs java" data-trim>
try {
something();
} catch (Exception ex) {
System.out.println(ex);
}
</code></pre>
</section>
<section>
<pre><code class="hljs c" data-trim>
FILE* f = fopen("someting.txt", "wb");
fprintf(f, "Done!");
fclose(f);
</code></pre>
</section>
<section>
<div>
Onde o erro foi tratado nisso?
</div>
</section>
<section>
<pre><code class="hljs rust" data-trim>
enum Result&lt;T, E&gt; {
Ok(T),
Err(E),
}
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
match File::create("something.txt") {
Ok(fp) =&gt; fp.write_all(b"Hello world"),
Err(err) =&gt; println!("Failure! {}", err),
}
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
match File::create("something.txt") {
Ok(fp) =&gt; match fp.write_all(b"Hello world") {
Ok(_) =&gt; (),
Err(err) =&gt; println!("Can't write! {}", err),
}
Err(err) =&gt; println!("Failure! {}", err),
}
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
let mut file = File::create("something.txt").unwrap();
file.write(b"Hello world").unwrap();
</code></pre>
</section>
<section>
<pre><code class="hljs rust" data-trim>
let mut file = File::create("something.txt")?;
file.write(b"Hello world")?;
OK(())
</code></pre>
</section>
</section>
<section>
<section>
<h2>Macros</h2>
</section>
</section>
<section>
<section>
<h2>Hora da anedota!</h2>
<img class="stretch" src="_images/senta-que-la-vem-historia.gif" alt="">
</section>
<section>
<p>localtime</p>
<p class="fragment">SimpleDateFormatter</p>
</section>
<section>
<h3>Rust resolveria isso?</h3>
<h2 class="fragment">Não</h2>
<h4 class="fragment">... na verdade, nem ia compilar.</h4>
</section>
</section>
<section>
<section>
<h2>Crazy stuff</h2>
</section>
<section>
<a href="https://medium.com/@shnatsel/how-rusts-standard-library-was-vulnerable-for-years-and-nobody-noticed-aebf0503c3d6">How Rust’s standard library was vulnerable for years and nobody noticed</a>
</section>
<section>
<a href="https://medium.com/@sgrif/no-the-problem-isnt-bad-coders-ed4347810270">No, the problem isn’t “bad coders”</a>
</section>
<section>
<img src="_images/rust-issues.png" alt="4.5k issues no Github" class="stretch">
</section>
<section>
<a href="https://rustup.rs/">rustup</a>
<div class="fragment">
<small>stable-x86_64-pc-windows-msvc</small>
</div>
<div class="fragment">
<small>armv7-unknown-linux-gnueabihf</small>
</div>
<div class="fragment">
<small>wasm32-unknown-unknown</small> <small class="fragment">(WebAssembly)</small>
</div>
</section>
</section>
<section>
<section>
<h2>Bibliotecas</h2>
</section>
<section>
<h3>Rayon</h3>
<pre><code>
fn sum_of_squares(input: &amp;[i32]) -&gt; i32 {
input.iter()
.map(|&amp;i| i * i)
.sum()
}
</code></pre>
</section>
<section>
<h3>Rayon</h3>
<pre><code>
fn sum_of_squares(input: &amp;[i32]) -&gt; i32 {
input.par_iter()
.map(|&amp;i| i * i)
.sum()
}
</code></pre>
</section>
<section>
<h3>Log-Derive</h3>
<pre><code>
#[logfn(ok = "TRACE", err = "ERROR")]
fn call_isan(num: &amp;str) -&gt; Result&lt;Success, Error&gt; {
if num.len() &gt;= 10 &amp;&amp; num.len() &lt;= 15 {
Ok(Success)
} else {
Err(Error)
}
}
</code></pre>
</section>
</section>
<section>
<section>
<h2>E quem usa?</h2>
</section>
<section>
<h3>Magic Pocket</h3>
<p>Dropbox</p>
<p>Petabyte storage</p>
</section>
<section>
<h3>Servo</h3>
<p>Mozilla</p>
<p>Base do Firefox Quantum</p>
</section>
<section>
<h3>Azure</h3>
<p>Microsoft</p>
<p>Usado na parte de IoT do Azure</p>
</section>
<section>
<h3>Tor</h3>
</section>
</section>
<section data-background='_images/thats-all-folks.jpg'>
<div class="semi-opaque">
<ul class="empty">
<li>Júlio Biason</li>
<li>https://functional.cafe/@juliobiason</li>
<li>julio.biason@pm.me</li>
<li><a href="http://presentations.juliobiason.net">http://presentations.juliobiason.net</a></li>
</ul>
</div>
</section>
</div>
</div>
<script src="reveal.js/lib/js/head.min.js"></script>
<script src="reveal.js/js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
// showNotes: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'reveal.js/lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'reveal.js/plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal.js/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal.js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal.js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>