Computer Science Educators Asked by ljrk on August 21, 2021
In our Bachelor curriculum the course Operating Systems and Computer Networks (5 CP) is designated to be taken in the second semester. Currently it uses C, and while I’m personally very fond of C, it does usually overwhelm the students to learn C enough in order to be able to complete the practical exercises.
However, the focus of the course is not to learn a language but rather the concepts and applying them in small exercises, while getting a "feel" for operating systems or low-level development.
Issues students had with C:
A few of these issues could be addressed with Rust:
Other languages and their issues:
However Rust has many abstractions that actually stop us from being able to really ‘go down’ the stack and look ‘into’ what’s happening (at least, without understanding the details of Rust which isn’t the goal). For example for the students to fiddle around with syscalls they are supposed to write a small cat(1) program using open,close,read,write(3) etc. There’s of course the libc
crate but using that basically requires knowledge of C and Rust to really deal with things. I thus drafted a small library which I currently host here with really thin abstractions around those syscalls that make dealing with them from Rust quite nicer. 1
The code logic is now quite similar, but hopefully the easier tooling helps the students:
ssize_t n = read(src, buffer, sizeof(buffer));
if (n < 0) { return 1; }
if (n == 0) { return 0; }
const size_t read = (size_t)n;
Becomes:
let read = match read(src, &mut buffer, BUFSIZ) {
0 => return 0,
n if n < 0 => return 1,
n => n as size_t,
};
And similarly
while (remaining > 0) {
ssize_t written = write(dest, &buffer[read - remaining],
remaining);
if (written < 0) { return 1; }
remaining -= written;
}
is now:
let mut remaining = read;
while remaining > 0 {
let written = match write(dest, &mut buffer[read - remaining..], remaining) {
n if n < 0 => return 1,
n => n as size_t,
};
remaining -= written;
}
I also think it’s far less confusing for students to have "return values" to be separate from program "exit codes". However I’d like to hear some opinions or get some feedback whether you think this is worth pursuing.
For those wanting to try this, in Cargo.toml
add:
[dependencies]
libc = "0.2"
ti3-rust = { git = "https://git.imp.fu-berlin.de/koenigl2/ti3-rust.git" }
Some things are lost when using Rust. Since cargo
now handles building, the possibility to learn about (Preprocessing) -> Compilation -> Assembly -> Linking is lost. While the goal is not to be CLI compilation magicians, I think understanding this pipeline does help to reason about certain OS behavior. However one might rightfully argue that this is simply too in-depth for a 5 CP second semester course anyway.
1 However this library should not be used in the real-world as it simply wraps the low-level functions in the libc with unsafe
blocks and does some ugly casting.
Trying to learn many things at once: A language, an operating system, creating command line tools, compilation, etc. goes against cognitive load theory. That is why so many students fail. Keep it simple teach one thing at a time. You will do it in less time to can then teach the other things, with time to spare.
As a tutor I have taught a student, to create various Unix tools using python. We made: cat
, ls
, tee
, grep
, etc. and a simple shell. It did not obscure anything about how operating systems work. It did reduce cognitive load
Correct answer by ctrl-alt-delor on August 21, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP