Building Extensible Systems
Over the past few years, Mozilla has developed Rust, a new systems programming language. Mozilla is about to release the alpha version of the language. In this course we will jointly study and explore the Rust language.
Rust aims to make systems-level (C/C++) programming safe. Here safety means both memory safety and concurrency safety. That is, programs can manipulate memory almost as freely as C-level programs but cannot accidentally corrupt memory, and programs can spawn parallel threads but cannot suffer from race conditions. Both goals are achieved with a sophisticated type system.
The challenge is whether programmers can understand and work with this type system to build systems or modify existing ones. This course is the first university-level attempt to answer this question. [Don’t worry, you are not alone. Several companies have already used Rust in production code, including for game servers, operating systems, and web browsers.]
Students are expected to know some C/C++, Java, and the fundamental differences between these two languages. The course will also rely on basic memories from Fundamentals I, II, and Logic.
The course will involve a significant writing component.
Announcements
Fri Apr 10 13:41:01 EDT 2015
explain the purpose of the existing code base and the original goal of your project; if you had to cut back or change goals, say so [1min]
recall the functionality of the existing code base, how to use it, and briefly demonstrate it [4min]
demo what you accomplished [5min]
describe the pre-existing code base, focusing on those modules with which your Rust code has to interface and/or the Rust code replaces [5min]
show-case your Rust extensions
Do not simply walk us through the code line by line.
Start with an overview of the key pieces—
relating them to bullet 4— and then focus on those parts of the Rust code that posed problems— both in terms of integration and performance [10min]
Do keep in mind that we will have a guest who knows Rust but does not know what your projects are about and what your plans were.
Also, think of the request to repeat some of your initial presentation as a chance to improve your presentation skills.
Schedule
day |
| time |
| presenters |
4/13 |
| 6:10--6:35 |
| Kelly & Nimick |
-- |
| 6:45--7:10 |
| Furtado & Ukani |
-- |
| break |
| |
-- |
| 7:25--7:50 |
| Corbett & Lin |
-- |
| 8:00--8:25 |
| Coates & Silva |
|
| |||
4/20 |
| 6:10--6:35 |
| Cheung & Jensen |
-- |
| 6:45--7:10 |
| Bower & Kolek |
-- |
| break |
| |
-- |
| 7:25--7:50 |
| Boehman & Tran |
-- |
| 8:00 |
| Good bye, grades |
The breaks are for slippage, set-up, and technical problems with overhead projections, etc. Do not plan on these extra minutes for your presentation.
Fri Apr 3 09:55:51 EDT 2015
Please see addendum at bottom of Reflective Essay.
Wed Apr 1 21:23:46 EDT 2015
On Monday, we will wrap up the Rust-C interaction segment. We will reserve some time for general questions on Rust topics that have come up while you have been working on your project.
The new due date for submitting the project is April 10.
Use the additional time to get further feedback on your memo. Some of you need this feedback more than others; you know who you are.
You will present the projects on April 13 and 20. Instructions on how to present the projects will appear here.
I have also rewritten the last homework (Reflective Essay). Take a look.
Thu Mar 26 10:12:42 EDT 2015
Reminder: tomorrow is the deadline for turning in drafts of your project memo to Ms. Biron. Submission of an electronic copy is fine. If you need an extra 24 hours, sending in the draft by late Saturday is acceptable.
Please hand in your draft together with (a copy of) the marked-up copy of your original project memo.
a description of the purpose of the code base;
the original goal of your project;
a description of the organization of the code base, as relevant to the changes that you are implementing;
a write-up of your accomplishmentsDo not write up a history of your activities; assess your successes and failures., that is, what you actually did;
a description of your failures, that is, discrepancies between your goals and achievements.
Fri Mar 13 17:14:08 EDT 2015
- present your code base from a client perspective:
what does it do, overview
how do I use it, concrete examples, demo if possible
what kind of role do I play when I use it
- what does the code base look like from the inside:
what are the key modules, architectures
how do they collaborate, process
which ones do we need to know about from the perspective of this project?
what do you wish to add to this code base? abstractly, examples, like bullet 1 above
how will you go about it? Which modules does my extension hook into? How?
Thu Mar 12 17:40:18 EDT 2015
concurrency-philosophers.rs presents a solution for the “N dining philosphers” problem
concurrency-barber.rs presents an Arc/Mutex solution for the basic “sleeping barber” problem, i.e., one barber serves an arbitrary number of customers
concurrency-barber2.rs supplements the Arc/Mutex solution for the sleeping barber with Semaphores
concurrency-barber3.rs presents a channel-based solution to the basic “sleeping barber” problem
concurrency-barbers.rs shows how to extend the channel-based solution for the basic problem to a barber shop with many barbers.
Thu Feb 26 10:02:32 EST 2015
See below for String.
Wed Feb 25 19:22:05 EST 2015
Any place you could return a new array, an iterator is probably better. (Think of iterators as optimizing arrays for one-pass access.)
Methods should take arguments (except for small Copy types) by reference, except when they actually need to take ownership. The only reasons to take ownership of an argument are to send it to another thread, to store it in a data structure for later, or to destructively consume it (à la into_iter).
Methods should take immutable references unless they actually need to mutate.
The difference between &mut String and &mut str is that the former is a string buffer with dynamic size, whereas the latter has fixed size. Methods should take the latter unless they need to change the size, because the former can always be viewed as the latter by the client.
(There's no use for &String for which &str isn’t better. [The exception is String::capacity(&self).])
As the manual says for std:str, ``String is used for an owned string.''
Clone when you need to both retain and give away ownership of something. (Typically this creates two copies of its mutable state.)
Cloning is the caller’s job, not the callee’s.
Boxes are for recursive data structures and owned trait objects, not for passing arguments or returning them.
Use generic types whenever possible. For example, if your method takes a &mut BufferedReader<StdinReader>, but the only method used is lines(), then have it take &mut B where B: Buffer instead.
Mon Feb 23 15:19:18 EST 2015
the proposed project
the organization and content, i.e., the description of the project and its code base
and style items, ranging from sentence organization to choice of words, from grammar problems to layout.
The opening specifies the project that you wish to extend, describes its purpose, and indicates how you wish to modify its functionality.
The middle supplements the project description. It also explains how the project’s code base is organized.
The third part identifies a missing piece of functionality. It should list its purpose and sketch its workings.
The last part sketches how you will go about adding the functionality to the code base, making references to terms introduced in step 2.
Leave a one-inch margin all around. It makes the page readable.
Add a noun to uses of "this" and "these." Otherwise the reference remains unclear.
Avoid "there is" and "there are". Certainly don’t pile them up.
Use colons ":" to introduce enumerations.
Reserve "you" for the recipient of the memo.
Note I understand that, outside of computer science, the word "user" is reserved for consumers of illicit drugs. But the usage is common now, so get used to it, too.
The word "however" is used to switch a paragraph’s line of argument from support for its thesis to a different/opposite point you wish to make in the following paragraph.
An m-dash consists of three hyphens and is attached to the surrounding words.
Replace "they" with "he/she" if you wish to accommodate the gender police. Otherwise you are likely to write sentences whose subject will fail to match the verb in numbers.
Thu Feb 19 19:20:44 EST 2015
make-up class tomorrow (Friday) evening at 6pm in WVH 166
Thu Feb 19 19:20:44 EST 2015
make-up class tomorrow (Friday) evening at 6pm in WVH 166
Wed Feb 18 13:27:26 EST 2015
What’s a letter?
At the information level, let’s define letter as a .. z and A … Z. At the data level, choose the natural representation.
And in this context, how should we deal with apostrophes?
Consider them as word terminators.
Fri Feb 13 10:09:19 EST 2015
Keep those dates open.
To: All Faculty
From: Stephen W. Director, Provost & Senior Vice President for Academic Affairs
Date: February 13, 2015
RE: Options for making up classes cancelled due to snow closings
As a result of winter weather conditions, classes on the Boston campus have been cancelled five times this semester, including two Mondays, two Tuesdays and one Wednesday. Because there are a number of Monday holidays during the Spring Semester, cancellation of Monday classes due to snow has had the greatest impact on the educational program. We appreciate the efforts of many faculty members who have already begun to make accommodations to assure that students learn all that was planned within each course.
While a number of courses have already scheduled make-up class sessions and course activities on an ad hoc basis, we will be using both Patriots Day (April 20, 2015) and Reading Day (April 23, 2015) as opportunities to schedule missed classes. To schedule a time for your class to meet during either of these days, or at another time that may work for you and your students outside of your assigned class hours, please use the Special Room Request Form found at www.neu.edu/registrar/schedfrms.html. The Registrar’s office will respond quickly to requests but will give preference to those classes that would have normally been scheduled on a Monday.
We recognize that the unprecedented snowfall has created a strain on all of our programs and there is no one solution to address this strain that will satisfy everyone. However, after a number of discussions with the academic deans, we feel this is the best alternative and we do appreciate everyone’s patience.
Thu Feb 12 09:42:53 EST 2015
Most of you came to see Jesse and me and got feedback on your proposed project. For the memo that is due tomorrow, please drop off the paper copy but also send Ms. Biron an electronic copy (PDF, Doc, etc) so that she can mark that up in case the weekend storm really comes through.
specify the chosen code (external purpose statement),
describe its internal organization, and
state the goal of your Rust extension.
For those of you who are still struggling with this choice, the ideal project is something people can download, run, and interact with (e.g., piping files into it, text console, or GUI interface). Your Rust extension should provide some additional functionality to such a project that becomes optionally visible. Typically this goal calls for small changes to the C code base, a Rust module, and a carefully constructed interface between the former and the latter.
Tue Feb 10 16:39:49 EST 2015
tomorrow (Wedn. Feb 11) from 3pm to 7pm in WVH 308b
Mon Feb 9 22:24:28 EST 2015
Also note, if the T is running again on Wednesday, I will run an "open house" for advice on your project selection. Please watch this space for specifics.
Sat Feb 7 15:30:05 EST 2015
As requested, I have asked Systems to install Rust and Cargo on their Linux systems, and they have already done so. When you see a Systems guy, thank him for the group’s prompt services.
Thu Feb 5 2015
make-up class tomorrow (Friday) evening at 6pm in WVH 366
Wed Feb 4 2015
Jesse has type-set his lecture notes on lifetimes and borrowing.
Given this code snippet,
use std::collections::HashMap;
fn main() {
let s = & String::from_str("hello");
let h = create_string(s);
println!("{}",h.get("hello").unwrap());
}
fn create_string<'a>(s : & String) -> HashMap<&'a str, usize> {
let mut hm : HashMap<&str,usize> = HashMap::new();
hm.insert(s.as_slice(),1);
return hm;
}
Why does this fail with a message about "not being able to infer the correct life time?"
You can see that the life time parameter ’a shows up in the result type but not in the argument. So, how can s can possibly be used to create a string slice that survives long enough?All string constants are string slices with a static life time. That is, the compiler hoists them out and creates a unique pointer for them—
like for symbols in a Lisp-style language. Now fortunately, the compiler provides a rather suggestive error message and following this message corrects the mistake:
fn create_string<'a>(s : & 'a String) -> HashMap<&'a str, usize> {
let mut hm : HashMap<&str,usize> = HashMap::new();
hm.insert(s.as_slice(),1);
return hm;
}
Tue Feb 3 2015
Also, apparently our selection of the final project is due on Friday? I’m not really sure what the criteria is for what we select. The three projects you listed don’t particularly interest me, but if I wanted to find another, what sort of attributes should we be looking for?
We welcome any project
whose source is in C (or C++ if you know enough to read the relevant part of the source),
that appeals to you in some way, and
for which you can think of some functionality that you would like to add.
fn parse_lines<'a, R: Reader>(mut reader: BufferedReader<R>)
-> HashMap<&'a str, usize> {
let mut wordcounts: HashMap<&str, usize> = HashMap::new();
...
}
that the string slices that get stuck into the hash map are created within parse_lines. By using String instead, this function gets through the borrow checker.
Sat Jan 31 2015
Last night we did not get to code-walk my
conventional-looking solution for Counting Words. Please do
take a look just so you understand that you can code in Rust in a style close to
the one you know from courses using C or C++—
Thu Jan 29 2015
make-up class tomorrow (Friday) evening at 6pm in WVH 366
Sun Jan 25 2015
After grading the memos/essays, I have added a section on Notes on Writing to the course site. It includes suggested readings, notes on how I evaluate your writing, and a sample essay on my favorite language. I urge you to read these hints because the remaining writing tasks are of a similar nature.
Note that the grade is primarily a judgment of how well you can articulate your points, how well you can organize them, and how directly you can support the chosen points. Secondary are flow/style, grammar/typos, and content, though if you call something "red" when it is completely "blue" I will deduct points.
Obviously the grade is completely independent of your choice of favorite
language. When I ask you to pick and describe your favorite language, I will not
call into question what you choose.If you ask me for my opinion
about your reasoning, I will explain to you why you are wrong. In case you are
curious, essays on both Ruby and Python received 10/10 grades as well as failing
grades—
Oh yes, and do read course announcements.
"Python is like a tupperware container, you can put soup or a chicken sandwich in it."
"Javascript is clay, she has borne children, she flirts."
Wed Jan 14, 2015
For our Building Extensible System’s essay assignment, are you expecting something that sway’s more towards the "poetic" side (for the average reader) or do you want it to be purely technical.
The choice is yours as long as the essay is descriptive not judgmental. "The car is red" is good, "the car has beautiful curves" is bad. Okay?
Sat Jan 10, 2015
Welcome!
Please reflect on all the programming languages you have experienced in the past. Then pick your currently favorite language and make sure it is installed on your laptop. Bring (1) a letter-size sheet with the name of your chosen language and (2) your laptop to the first meeting. Fold the sheet and place it front of you on your table/desk/chair in class. We will conduct live-coding sessions in these languages.