The Summer of Rust
notes date: 2018-10-07
source links:
source date: 2018-08-01
My language history
- C, started learning it in college
- C was programming me more than I was programming it
- C++
- one of the professors in the department overheard some of my enthusiasm about C++ and like a grim apparition from the future told me once you’ve written a hundred thousand lines of C++ you won’t love it any more and I was like no way man I love this stuff or whatever.
- fast forward maybe two years later and I am in hour three of debugging what I now know to be two totally distinct compiler bugs […] and every time I try to isolate one of them the other one would come and start punching me in the face and I go to try to isolate that […].
- and I realize I can write a linked list really really fast in C, I guess as fast as I can type
- Java (when working at Sun)
- sticking with C
- one of the things that we do that i’m amazed the rest of humanity doesn’t do is structure prefixing. in C, every member of a structure has a prefix that is quasi-unique to that structure, and when you have [thousands or millions] of lines of code, if that thing is called i or next and you’re using cscope […] you would have no chance of finding this thing
- Ruby (on Rails)
- In 2005, the Ruby on Rails video broke the belief that everything in the future would be written in Java
- Visited Twitter in 2007, they had a problem where a request would take 460 milliseconds. They were spending all their time in bcopy, bcopying symbols out of their stack. Deep in the rails app, instead of iterating through an array from first to last elements, it blasts through the array–even a 4 element array–until it gets an out of bounds exception, then Ruby compiles an exception (full stacktrace and all, like a 16K string buffer), and Rails catches the exception and throws all of that away.
- Javascript
- It was LISP in C’s clothing
- Perl
- Perl is really an awful language to do software engineering in
- It just tried to bolt on a lot of concepts like object orientation, exceptions, …
- I got to like 10 thousand lines of perl and had this moment of, like, I am in the wrong language, this is not right, none of this is right.
- Javascript
- Elective Javascript circa 2008 was like online dating circa 2000–definitely not something you brag about
- NodeJS took javascript, but added v8 and effectively the unix abstractions. It was superfast. The company behind it was Joyent.
- Javascript is the failed state of programming languages. It is an absolute free-for-all. Anybody can do whatever they want, whenever they want. It is ruled by feuding warlords. Everybody kind of gets their own warlord and then life isn’t so bad, right, they can get their food convoys through.
- What happened was the values that we had for Node were values that Node never had for itself. Because Node – and it kills me to say this – but this is the truth: Node is javascript
- Javascript’s values are all about growth and accessibility.
- It took Node in a lot of directions that were not directions we would’ve taken it
- Promises was one where it kind of totally melted down.
- God forbid you have a type error deep in something you called via a promise, because it’s going to be really excruciating to figure out what’s going on. It’s like, “Okay, if you have a typo in your source file we are gonna pick a relative of yours, at random, in a foreign country, and burn their house down. That’s how you’ll know.” It’s like, “can you just like give me a phone call, an SMS, is this really the way you’re gonna do it?”
- We still exist on our own crazy island of javascript plus C hybrids with all this discipline around it about how we write and debug. We’ve gotten Node to work well for us. We’ve been able to carve out our own little villa in the failed state. We’ve got armed guards everywhere, but it’s fine. Like, relax at the pool, it’s fine. It’s fine. Just travel with a security detail.
- It’s fine for now, but it’s not a future.
- The talk I ended up giving (about Node in 2015) “A Platform as a Reflection of Values”
What are the candidates to replace C
- C++: NO!
- Go
- Go is kind of a lateral move from Node. It’s going from a failed state, to a very strangely autocratic one.
- I wish Go would just say “we don’t feel like it” a lot more frequently
- It’s GC’d
- GC languages are not fine for the kind of software I want to spend the back half of my career on
- Cassandra - when you got a database that’s on a like 185 millisecond vacation and the cassandra experts are like “that’s pretty good, it sounds like you tuned your GC”
- Error handling
- C is infamous for this: “does 0 mean success?”
- Go’s solution is very boilerplatey (which creates copy-paste risks)
Rust
- a non-GC’d language, but you don’t allocate or free memory either – the compiler statically figures out when you’re done with things.
- The way Rust deals with errors
- the Result type, with pattern matching and decomposition
?
on a function call (which unwraps result if succeeded, or propagates the error if an error)
- The zeitgeist of Rust is writing load-bearing software that will survive us
- “if you want code by the pound, I am not your guy” - Peter Memishian
- Rust has true or hygienic macros (so you can generate better code faster)
- It’s super fast
- even C can’t be as fast on some things; like, if you call into a function that is externally linked, the C compiler can’t assume anything about the state of memory when control returns, so it needs to forcibly reload all memory
- you want to be far enough in that by the time you have your first fight with the borrow checker, you are willing to accommodate it
- two great books
- The Rust Programming Language
- Programming Rust