cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
cristicbz's comments
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
Well and generics & traits. 99% of the places where C++ programmers use templates, they would use generics in Rust. `template std::vector<T>` <-> `Vec<T>` etc.
It's only the niche metaprogramming ability of C++'s templates that would be replaced with macros.
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
auto v = std::vector<int> {1, 2, 3}
for (auto x : v) {
if (x > 0) {
v.push_back(-x);
}
}
The above may segfault, do what you expect it to, run forever etc. Unchecked indexing, branching on uninitialized data etc.Rust frees you from _all_ of these things and offers a bunch of further advantages, most notably: data race freedom. You can actually share data between threads and keep your sanity.
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
It's hard to quantify how much time _this_ project took, since when I started a year ago I knew nothing about Doom or Rust. If I started writing it now from scratch, I could probably hammer it out in a working week. A better programmer could probably do it in a weekend. It's neither very big nor very hard.
But that's not how programming works, is it? In fairness, you'd need to count some of the time I spent working on a lot of other random Rust side projects and reading blog posts over the last year, while only spending a couple of hours ever other week or so on rust-doom.
> Certainly wrestled with the ownership system for a while
I think my background in modern C++ helped me a lot with this, since the "one owner per thing, move semantics" model is how you're supposed to write C++ too.
That said, figuring out the cleanest design is not easy and I'm still wrestling with it today. The code was an absolute mess last year and now it's better, but still needs plenty of work: just yesterday I decoupled WAD parsing from the rest of the code properly (https://github.com/cristicbz/rust-doom/pull/53).
I'm still learning a lot a year after dedicating all my free-time programming to Rust.
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
cristicbz | 10 years ago | on: Rust-Doom: A Doom renderer in Rust, with no unsafe code
cristicbz | 10 years ago | on: Announcing Google Cloud Bigtable
#!env bash
f () {
...code
...code
...code
}
f
Hence a partial stream will do nothing (syntax error, missing brace to be precise).cristicbz | 11 years ago | on: Some notes on Rust
1. A tiny function which loads textures. I was fooling around with optimising load speeds. The actual speedup I got was insignificant and I really should revert it to safe code.
2. A silly getter on the transformation matrix---another misguided attempt at a speedup; no reason to use UnsafeCell instead of RefCell. Should revert.
3. Casting buffers from files as structs. This is safe for any buffer the same size as a Copy struct, std offers no such function, so I do. Unsafety is isolated in two small functions (one for T and one for Vec<T>), all its callers are safe.
4. Interacting with OpenGL. Fair enough, this happens all over the place, but it's not actually unsafe. The OpenGL bindings library didn't take much care to only mark unsafe operations as such, and all GL calls are marekd unsafe---which is why I wrap them up in a macro which peforms the operation in an unsafe block and panics on any error. I should port my code to glium and then this would go away as well.
*better formatting
cristicbz | 11 years ago | on: A Doom Renderer written in Rust
cristicbz | 11 years ago | on: A Doom Renderer written in Rust