-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·186 lines (170 loc) · 11.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Andrew Clarry Blog</title>
<link rel="stylesheet" href="/theme/css/main.css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="/">Andrew Clarry Blog </a></h1>
<nav><ul>
<li><a href="/category/blog.html">Blog</a></li>
</ul>
</nav>
</header><!-- /#banner -->
<aside id="featured" class="body">
<article>
<h1 class="entry-title"><a href="/getting-to-rust.html">Getting to Rust</a></h1>
<footer class="post-info">
<span>Wed 28 August 2019</span>
</footer><!-- /.post-info --><p>A few years ago, I decided to hop on the FOSS development train and contribute to a
project which seemed pretty neat: the reference compiler for the Rust programming
language. Coming from a small amount of poking at C++ and Arduino from the safety of
garbage collected languages, Rust seemed to be full of good ideas. Even as a wee novice
programmer, I knew the danger of buffer overflows and use after free. I also appreciated
Java's type system checking my work for me, and Rust's familiar syntax and functional
programming idioms made it seem like *a cool thing* to try out - a programming language
<em>which let me use all the power of my computer</em> like C or C++, but with all the fancy
"modern" stuff that came from functional languages and strong type systems.</p>
<p>As most Rust programmers will warn you, I had a difficult time getting comfortable with
Rust. A lot of the language is very familiar - structs, objects, variable declaration,
and so on. But Rust's main selling point is its strictness about data ownership, and the
complexity of the ownership system required me to think hard about exactly where the data
was going, something I never really had to do before. Thankfully, the issue I latched
onto in the compiler's github repo was pretty simple - after getting my head around the
relevant parts of the vast code base, it mostly amounted to changing some of the classes
used and settling on good message text and behaviour. </p>
<p>Feeling validated (but a little exhausted) by my accepted pull request, I tried some more
complex projects. But my will was utterly broken by another aspect of the Rust language:
lifetimes. There comes a time in every nontrivial Rust program's life where the compiler
can't figure out data ownership on its own. More or less, it can't keep good enough
track of objects to be able to guarantee memory isn't used after the corresponding
objects have been destroyed. In these instances, the compiler whips the ball back into
the programmer's side of the court and requires some variables to have annotations
describing how long they are required to live for. Using these annotations, the compiler
can properly track the entire lifecycle of a block of memory and make sure it is not used
after it is freed or otherwise rendered unusable.</p>
<p>To me, this was a brick wall: the syntax was completely alien, I didn't understand how or
why the compiler decided where annotations were needed, and when tasked with actually
annotating a function it took me ages to figure out what my objects were actually doing
and how to describe them in the language of lifetimes. Trying to work through one
particular compiler error, I abandoned my fledgeling Tetris clone and moved on to gentler
pastures, never to return in earnest. I've kept up with new releases and some of the big
libraries, but I've never felt comfortable enough with Rust to start any projects with
it. </p>
<p>When I took it upon myself to try to get a solid grasp of C and modern C++, some of those
gears started turning again.
Working through some toy C and C++ programs, I was reminded of my struggles getting up to
speed with Rust. Some things were familiar: it turns out the syntax and semantics related
to pointers aren't just similar in Rust and C; they're basically identical. But the
heart of my problem was that while I understood what Rust was doing and what the problems
it tries to solve were, I didn't really understand those problems themselves. In my time
writing software in Python and Java, I never had to worry about when an object would be
freed or pointers hanging around in data structures far away from the original object.
While I understood that attempting to use memory that has already been freed, or files
which have already been closed, was quite a bad thing, I didn't understand how much those
issues interfered with the day-to-day software development process. The moment I
understood that you didn't have to be an idiot to put a use after free into your code was
when I finally <em>understood</em> what Rust was doing. References are just pointers; but when
you're designing software, a pointer should never just be a pointer. That's why Rust has
the totally separate <code>&</code> and <code>&mut</code> (and, not so coincidentally, why C++11 introduced
smart pointers).</p>
<p>I'm not entirely sure where I'm going with this, but my experience with learning Rust was
the first time that I recognized myself being blocked on a topic by a lack of
experiential understanding of its background. The novelty of that experience alone was
enough to warrant a closer inspection, and after a lot of thought I think it is the
programming equivalent of learning a simplified mathematical model before the more
accurate (but complex) one. There is only so much new information we can absorb before it
needs to be cemented.</p>
<p>In my case, I am an extreme "learn by doing" person, so upgrading from some toy Rust
programs to a medium-sized self guided one seemed like the logical way to get the basics
of Rust down. Unfortunately, Rust does not present a way to navigate a larger undertaking
like that without wading into its more advanced topics. This is a place where garbage
collected languages - and, for their credit, C and archaic C++ - shine. You can write a
naïve Python or Go program without worrying about what's happening with your memory or
the shape of your call graph, and it'll do something. You'll hit bugs big and small and
should never work on software being used by other people, but you'll feel good about the
foundations of how to actually get stuff done in those languages. Rust is insistent about
hitting you over the head with a sack of bricks until you understand all the things that
make Rust uniquely Rust. After that and only after that, can you get up off the ground
and do what you originally wanted. At least they have the courtesy to warn you up front –
"fighting with the borrow-checker" didn't become a meme for nothing.</p> </article>
</aside><!-- /#featured -->
<section id="content" class="body">
<h1>Other articles</h1>
<ol id="posts-list" class="hfeed">
<li><article class="hentry">
<header>
<h1><a href="/whats-everyones-least-favourite-season.html" rel="bookmark"
title="Permalink to What's everyone's least favourite season?">What's everyone's least favourite season?</a></h1>
</header>
<div class="entry-content">
<footer class="post-info">
<span>Mon 20 June 2016</span>
</footer><!-- /.post-info --> <p>So, I got a text out of the blue this morning with my friend asking me to help
with my purely academic experience in game theory. I like to help others
(and be distracted from real-world responsibilities), so I agreed to help.</p>
<h1>The setup</h1>
<p>My friend's office was playing a variation of the el Farol Bar problem, a
classic problem in game theory.
Game Theory is a branch of economics …</p>
<a class="readmore" href="/whats-everyones-least-favourite-season.html">read more</a>
</div><!-- /.entry-content -->
</article></li>
<li><article class="hentry">
<header>
<h1><a href="/cabinet-qualifications.html" rel="bookmark"
title="Permalink to Cabinet Qualifications">Cabinet Qualifications</a></h1>
</header>
<div class="entry-content">
<footer class="post-info">
<span>Sun 08 November 2015</span>
</footer><!-- /.post-info --> <p>There's been a lot of <em>discussion</em> recently about the place of merit in Canada's executive branch. As a quick recap, the country's Cabinet, made up of elected MPs chosen by the Prime Minister, are the main part of government that oversees the government's operation, proposes laws, and generally calls the shots. The new Liberal government has found a first in producing the first cabinet in Canada's history which has just …</p>
<a class="readmore" href="/cabinet-qualifications.html">read more</a>
</div><!-- /.entry-content -->
</article></li>
<li><article class="hentry">
<header>
<h1><a href="/hello-world.html" rel="bookmark"
title="Permalink to Hello, World!">Hello, World!</a></h1>
</header>
<div class="entry-content">
<footer class="post-info">
<span>Tue 03 November 2015</span>
</footer><!-- /.post-info --> <p>Hey!</p>
<p>I'm Andrew Clarry. You might know me, and that's cool, thanks for reading. I would probably find it even cooler if you were reading this and you don't know me, but don't take it personally.</p>
<p>Continuing on the assumption that you know me, you know I'm fond of the word vomit. If you pay attention closely, you'd also know that there's a lot of stuff I find really cool …</p>
<a class="readmore" href="/hello-world.html">read more</a>
</div><!-- /.entry-content -->
</article></li>
</ol><!-- /#posts-list -->
<p class="paginator">
Page 1 / 1
</p>
</section><!-- /#content -->
<section id="extras" class="body">
<div class="blogroll">
<h2>blogroll</h2>
<ul>
<li><a href="http://getpelican.com/">Pelican</a></li>
<li><a href="http://python.org/">Python.org</a></li>
<li><a href="http://jinja.pocoo.org/">Jinja2</a></li>
</ul>
</div><!-- /.blogroll -->
<div class="social">
<h2>social</h2>
<ul>
<li><a href="https://ca.linkedin.com/pub/andrew-clarry/97/b25/294">Linkedin</a></li>
<li><a href="https://github.com/aclarry">Github</a></li>
</ul>
</div><!-- /.social -->
</section><!-- /#extras -->
<footer id="contentinfo" class="body">
<p>Powered by <a href="http://getpelican.com/">Pelican</a>. Theme <a href="https://github.com/blueicefield/pelican-blueidea/">blueidea</a>, inspired by the default theme.</p>
</footer><!-- /#contentinfo -->
</body>
</html>