News for hackers. Stuff that matters.
Re:A pure JavaScript implementation of Git for Node and brow... by MikkoFinell on Thursday May 17, 2018 @11:15AM (#17092001)
Which information in particular is missing from the C type system in your opinion?
Re:A pure JavaScript implementation of Git for Node and brow... by littlestymaar on Thursday May 17, 2018 @02:03PM (#17093768)
The two major important improvements Rust type system brings are :

- the ownership of your object (who is in charge of free-ing it) and the lifetime of the pointers that targets this object. (the whole ownership system & the borrow-checker)

- is some data-structure thread-safe. (the Send and Sync traits)

With those, you can take any Rust code and play with it without having to ask existential questions. Your code will never segfault or exhibit a strange intermittent bug ones you add multi-threading.

Less important but still really convenient on a daily basis:

- will this function mutate the value I give it. (&mut pointers)

- has this variable already been consumed, which means I should not touch it anymore (affine type)

Re:A pure JavaScript implementation of Git for Node and brow... by MikkoFinell on Thursday May 17, 2018 @02:54PM (#17094323)
> the ownership of your object (who is in charge of free-ing it) and the lifetime of the pointers that targets this object. (the whole ownership system & the borrow-checker)

Having to bear the cognitive burden of making the lifetime explicit in all of the code is a steep price to pay for the benefit of securing the small subset of the code that is actually complex enough to potentially cause a problem. I wouldn't mind having such a feature be optional though, so that you'd enable it for the most precarious parts, something like a safe{} block rather than unsafe{}.

> will this function mutate the value I give it. (&mut pointers)

We already have const. Yes I agree it's better to enable by default.

Re:A pure JavaScript implementation of Git for Node and brow... by littlestymaar on Thursday May 17, 2018 @04:44PM (#17095521)
> Having to bear the cognitive burden of making the lifetime explicit in all of the code is a steep price to pay for the benefit of securing the small subset of the code that is actually complex enough to potentially cause a problem. I wouldn't mind having such a feature be optional though, so that you'd enable it for the most precarious parts, something like a safe{} block rather than unsafe{}.

It's obviously a learning curve burden but now that I use the language on a daily basis, it doesn't really slows me down. The thing is you don't often need to annotate the lifetimes by hand since the compiler elides the most common case. In practice, the time you need to do the annotation is often what you call «actually complex enough to potentially cause a problem».

Re:A pure JavaScript implementation of Git for Node and brow... by Too on Thursday May 17, 2018 @03:19PM (#17094590)
Does rust have something like shared pointers? In c++ that's usually a quite easy way to bail out of the cognitive burden of understanding complex lifetimes.
Re:A pure JavaScript implementation of Git for Node and brow... by steveklabnik on Thursday May 17, 2018 @03:27PM (#17094657)
We have two! Rc is non-atomic, and therefore not threadsafe. Arc is atomic, and therefore threadsafe. The compiler can let you know if you are using Rc inappropriately, so you get some extra speed if you are single threaded.
Re:A pure JavaScript implementation of Git for Node and brow... by weberc2 on Thursday May 17, 2018 @01:39PM (#17093500)
For better or worse, Rust has a lot more built into its type system, including semantics for type safe generics and safe memory management. This makes it harder to write a correct Rust program, but also it makes it harder to write an _incorrect_ Rust program.