back

by jeffreyrogers·11y ago·view on hn ↗
My impression of Rust is that it focuses too much on safety at the expense of making it hard to do what you want, especially when dealing with low level things.
2 comments
Yes, hard to accidentally introduce buffer overflows, memory leaks and other things you probably hadn't fully considered.

If the Rust compiler is stopping you from doing something, there's good chance you really shouldn't be doing it.

... but I like adding different kinds of numbers without compile errors. I get that floating point and integers can be dangerous together, but forcing me to cast in order to add an i32 to an i64 seems like a case of missing a reasonable default.
Preventing buffer overflows requires runtime checks. That's a performance hit. Memory leaks require either GC or a restrictive type system. The first is another performance hit, the second is cumbersome to use.

I think Rust does a lot of things nicely, but I don't expect it to replace C simply because it adds a lot of complexity that people don't really want to deal with.

Buffer overflows occur in C because the language doesn't force programmers to perform those runtime checks and so many don't (or don't do it correctly).

Rust makes sure you are checking those things. Some of those checks are only at compile time and have no runtime cost. Others have a runtime cost but in the vast majority of situations the 'performance hit' will be negligible. Anywhere it is important you would rearrange your code to move the checking out of any critical path.

Note that it's still the same thing you'd have to be doing in C anyway to be both correct and fast. Rust just makes sure you don't forget the correct bit.

http://doc.rust-lang.org/nightly/intro.html#safety-<em>and</...

Regarding complexity and being cumbersome, Rust increases compile time dependency, but reduces debugging complexity.

Personally I would rather spend a bit more time at compile time thinking about memory ownership than spending hours (or even days/weeks) tracking down memory problems.

> Preventing buffer overflows requires runtime checks.

Incorrect.

"By using theorem proving and strict type checking, the compiler can detect and prove that its implemented functions are not susceptible to bugs such as division by zero, memory leaks, buffer overflow, and other forms of memory corruption by verifying pointer arithmetic and reference counting before the program compiles."[0]

0: http://en.wikipedia.org/wiki/ATS_%28programming_language%29

Here's a question: if you write the same code in Rust and C and Rust refuses it on the grounds that you did something wrong and C accepts it, how likely is it that the C code is going to crash at runtime, and you'll have to fix it anyway?