back

by jeffreyrogers·11y ago·view on hn ↗
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.

2 comments
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