News for hackers. Stuff that matters.
Re:The Problem with Friendly C by Peaker on Thursday December 24, 2015 @04:38AM (#10787662)
I love the ideas behind Rust. I don't think it can replace C for all use-cases.

C has the use-case of zero-dynamic-allocations. AFAIK, Rust is not very compatible with that mode of use.

Re:The Problem with Friendly C by scott_s on Thursday December 24, 2015 @10:20AM (#10788410)
As far as I know, C and Rust give you the same opportunities to work with stack-allocated values.
Re:The Problem with Friendly C by Peaker on Thursday December 24, 2015 @12:45PM (#10788943)
It's not just stack allocations, it's support for intrusive allocations, pointers not always conforming to simple ownership semantics, etc.
Re:The Problem with Friendly C by catnaroek on Thursday December 24, 2015 @10:23AM (#10788422)
Huh? If you don't want any dynamic allocation (or any other features that require support from a runtime system), you can use `#![no_std]` and instead use `libcore` directly. This is how the standard library itself is implemented.
Re:The Problem with Friendly C by Peaker on Thursday December 24, 2015 @12:43PM (#10788931)
The problem, as I understand it, is that Rust's ownership semantics don't accommodate for the kinds of programming needed by 0 dynamic allocations.

Lots of intrusive nodes pointing freely at one another, is an example. I've heard some Rust libraries approximate intrusive allocations almost perfectly, but not quite perfect.

Re:The Problem with Friendly C by steveklabnik on Thursday December 24, 2015 @01:26PM (#10789097)
As long as you're willing to use unsafe, you can write things exactly as you can as in C. That's of course, not as satisfying as not needing to, but by encapsulating that in a library and providing a safe interface, downstream users still get the benefits.
Re:The Problem with Friendly C by Peaker on Friday December 25, 2015 @02:38AM (#10790670)
Can a safe interface always be provided?
Re:The Problem with Friendly C by steveklabnik on Friday December 25, 2015 @09:55AM (#10791354)
I can't say that I'm able to speak to every single possible program ever, but at _some_ level, it should end up safe, yeah.
Re:The Problem with Friendly C by catnaroek on Thursday December 24, 2015 @04:00PM (#10789557)
Rust's ownership and borrowing rules are entirely a compile-time thing: they just determine what objects can be safely used, and when. There is absolutely no need to use dynamic allocation to benefit from Rust's ownership and borrowing checks. And none of the other core language facilities (primitive types, unsafe pointers, fixed-size arrays) require dynamic allocation either.

What does require dynamic allocation is using boxed objects and dynamically sized collections (such as vectors and tree maps), which are provided by `libstd`, but not by `libcore`. Think of using `libcore` as using C or C++ in freestanding mode.

Re:The Problem with Friendly C by Peaker on Friday December 25, 2015 @02:39AM (#10790671)
As far as I know, nobody managed to create a comprehensive intrusive data structure library that behaves as optimally as in C, due to the ownership semantic restrictions.
Re:The Problem with Friendly C by catnaroek on Friday December 25, 2015 @06:51AM (#10791004)
So just bypass the ownership checks, with `unsafe`. It gives up on memory safety, but you still keep all the other benefits of a modern language: algebraic data types, pattern matching exhaustiveness checks, parametric polymorphism, etc. So, even when writing `unsafe` code, Rust is strictly superior to C and C++.

Also, I would contend that, for the vast majority of programs, the benefits of a simple, hierarchical, statically enforceable resource management scheme like RAII outweigh the downsides. Programs that need more sophisticated approaches are a very small minority.