News for hackers. Stuff that matters.
Re:Never patterns, exhaustive matching, and uninhabited type... by mlevental on Saturday August 18, 2018 @09:36AM (#17788387)
I wrote a fair bit of go at my old job and I just finished a small internal rust utility at my current job. i liked go at first but then got completely fed up with the error handling, the module/folder nonsense, having to define the same function over and over for different primitive types when it came up, and nil. so I picked up rust. it's miles better. the syntax is not as bad you imagine - my utility is about 1000 lines and there are no lifetime parameters anywhere. the functional stuff is clean (closures, iterators, match). there are real enums (none of that iota nonsense) which as a "mature" developer have become integral to the design of any system for me. writing macros is easy (basically just like code gen in go). the borrow checker isn't that hard to satisfy - only one thing was a head scratcher and #rust-beginner helped me out there. cargo is great and so is RLS. there are a surprisingly large number of libraries given how young the language is (fewer than go for sure but enough that I didn't have to implement anything tedious myself). I mean it's just an all around pleasant experience and you're guaranteed to be writing performant (zero cost abstractions) safe code. how can you beat that? the only thing I miss from go are goroutines and the lightning fast compiler (but the rust compiler is plenty fast for how much it does). so I will probably use rust for everything other than what's fit for a python script from now on.
Re:Never patterns, exhaustive matching, and uninhabited type... by pierrec on Saturday August 18, 2018 @09:50AM (#17788447)
>you're guaranteed to be writing performant safe code

Let's not get overboard here

Re:Never patterns, exhaustive matching, and uninhabited type... by mlevental on Saturday August 18, 2018 @10:15AM (#17788552)
edited to clarify with zero cost abstraction
Re:Never patterns, exhaustive matching, and uninhabited type... by Nokinside on Saturday August 18, 2018 @10:29AM (#17788599)
> and you're guaranteed to be writing performant safe code

That's very far from truth.

Re:Never patterns, exhaustive matching, and uninhabited type... by smolder on Saturday August 18, 2018 @11:41AM (#17788968)
The problem here is the ambiguity of "safe", I think. Saying rust generates "guaranteed safe code" seems to imply that compiled rust can never do anything wrong, which isn't true.

Rust does make guarantees about certain kinds of safety, when not using unsafe {} blocks. You get memory safety and freedom from data-race issues. I don't know if any other languages offer that without incurring runtime costs.

Slow rust code is also possible, but your code can't really be slow because it is written in rust, in the same way that c doesn't get in the way of performance.

[dead]
Re:Never patterns, exhaustive matching, and uninhabited type... by Nokinside on Saturday August 18, 2018 @11:02AM (#17788780)
>If you have a meaningful contribution to conversation (e.g. you can enlighten us to instances where rust compiles down to inefficient or unsafe code) then make it.

This should be applied to your original unsubstantiated claim.

Rust has some features that improve safety. Writing code in Rust does not generate safe code.

Re:Never patterns, exhaustive matching, and uninhabited type... by bluejekyll on Saturday August 18, 2018 @11:13AM (#17788830)
I’m not sure what you mean by this: “Writing code in Rust does not generate safe code.”

I mean philosophically you could say there is no safe code, but then what’s the point of any language improvement.

Perhaps you mean that Rust has unsafe, which allows you to write unsafe code in Rust. But technically that term is reserved for the developer to make a claim that though the compiler can’t determine the safety of this code, the developer is claiming it is safe.

Then there is safe Rust, if you write safe Rust, the guarantees that the program output is safe are pretty high. Given that no software is devoid of bugs, it’s obviously not 100%.

So do you have a specific argument your making about why Rust is not safe? Or is it a general comment about software?

Edit: I suppose you could be pedantic in that rustc doesn’t generate code, but technically it does, mir and then llvmir. That code then gets compiled to platform specific binaries.

Re:Never patterns, exhaustive matching, and uninhabited type... by Nokinside on Saturday August 18, 2018 @11:32AM (#17788927)
> mean philosophically you could say there is no safe code, but then what’s the point of any language improvement.

I have been writing safety critical code for living, so I think that saying that code "is safe" because it is written in some language is categorical error (not just error of degree) unless it is a language enables formally proofing correctness.

You can take fundamentally unsafe language like C. Restrict to subset of it MISRA C and use external static code analysis like Astree that that uses abstract interpretation to prove that there are no run time errors: no memory errors, no division of zero erros, no out-of-bounds array indexing, floating-point or integer overflows, loops always terminate, floating point rounding errors stay within specified limits etc. Something that Rust does not have.

Rust has some potential and there are some companies that attempt to provide tooling to make it possible to write safe Rust code, but it's not there yet.

Re:Never patterns, exhaustive matching, and uninhabited type... by Rusky on Saturday August 18, 2018 @01:21PM (#17789491)
That sounds exactly like an error of degree- Rust does have "no memory errors" proof tools already, built into the language.
Re:Never patterns, exhaustive matching, and uninhabited type... by mlevental on Saturday August 18, 2018 @11:14AM (#17788835)
>This should be applied to your original unsubstantiated claim.

my meaningful contribution is a first hand account of my experience with a variety of the aspects of using rust. one potentially imprecise sentence doesn't negate that contribution. you on the other hand with completely contentless sentence fragments are contributing absolutely nothing to the conversation.

Re:Never patterns, exhaustive matching, and uninhabited type... by dwaltrip on Saturday August 18, 2018 @09:07PM (#17791904)
"Guaranteed" is a very strong word. It's okay, though. Just admit that you overstated something, and then easily move on with your life. No big deal.

There is power and freedom in the act of letting go of former actions and moving forward, from time to time. If someone judges you for making a small mistake, maybe they are the one with the issue.

This is a lesson I'm still practicing as well, so this comment is just as much a reminder to myself.