News for hackers. Stuff that matters.
Re:Rust vs. Go by derefr on Wednesday January 18, 2017 @05:32PM (#13431012)
"Two big conclusions" is a good way to put it.

I would phrase it like this:

• Go is a useful, safe subset of C (with a rather expanded libc.) Go lets you do fewer things than C (e.g. hard real-time things; processor-optimized things) but for most people, they don't need those things, and delving into them was what seeded the bugs into their C/C++ projects in the first place, completely unnecessarily.

• Rust is a formalization/codification of idiomatic C++. It's not a subset; it's a rethink, like Plan 9 is a rethink of Unix. You can do everything in Rust that you can do in C++, and the compiler will catch (nearly) all the bugs you would have left in the equivalent C++ project.

In other words, Go says "you don't need this"; Rust says "if you're so sure you need this, let's ensure you do it right."

For any given piece of code, either Go's assertion or Rust's assertion could be "correct." You either need the things only Rust lets you do, or you don't.

For a large codebase, though, I expect the answer is actually nearly always going to end up somewhere between. Big apps or libraries always have that one part that does heavy lifting and has to go fast, but go fast correctly; and 99% that doesn't.

Thus, I envision the future of many "systems software" codebases to look like this:

1. (1% of LOC) an "engine" library, written in Rust, which compiles to a C-ABI shared object;

2. (3% of LOC) an "engine wrapper" library, written in Go, which imports the "engine" object using Go's C FFI and then exposes a safe Go API to it—and also, the tests for the engine library, written in Go because it's easier;

3. (96% of LOC) the app itself, written in Go, which calls into the "engine wrapper."

Re:Rust vs. Go by civility on Wednesday January 18, 2017 @10:00PM (#13432601)
> Rust is a formalization/codification of idiomatic C++

Idiomatic C++ favors values and copy semantics. Rust favors references and move semantics. C++ has function and method overloading, and Rust does not. There are so many places where Rust chose exactly the opposite of "modern" C++ that calling Rust a codification or formalization of C++ makes no sense at all to me. Rust has some great features, and C++ has a lot of warts, but Rust is definitely not an improved C++.

Rust seems like a reaction to problems in C++, but for many design decisions I think they erred on the side of doing the opposite of C++ and ignored the things C++ does well.

Re:Rust vs. Go by moosingin3space on Thursday January 19, 2017 @02:38PM (#13438804)
> ignored the things C++ does well

What are you looking for that Rust is missing?

Re:Rust vs. Go by civility on Saturday January 21, 2017 @03:59AM (#13449428)
I wouldn't use the word "missing". I believe several of the Rust language designers are very familiar with C++, and to say that something is missing implies it was an oversight or an accident, or maybe they'll get to it later. Instead, I believe they don't value some of the powerful features in C++ and ignored the fact that other people find those features very valuable.

Here's an example that has bitten me several times now. Try and implement the following C++14 code in Rust:

    template<class T>
    struct Something { T a, b; };

    template<class S, class T>
    auto operator *(const S& x, const Something<T>& y) {
        return Something<decltype(S() * T())> {
            x*y.a, x*y.b
        };
    }
There are ugly workarounds, and I'm certain they have their reasons, but it's so much simpler and cleaner in C++.
Re:Rust vs. Go by msingle on Wednesday January 18, 2017 @06:50PM (#13431623)
Bradfitz (a member of the Go team) has said he would love to see OS / kernel level stuff done in rust and every thing above it in go.
Re:Rust vs. Go by soulbadguy on Wednesday January 18, 2017 @11:15PM (#13432956)
> You can do everything in Rust that you can do in C++, and the compiler will catch (nearly) all the bugs you would have left in the equivalent C++ project.

This is a bold claim, IMO somehow misleading. To "do everything you can do in C++", you have to use the unsafe part of rust, where you essentially lose of the compiler guaranty. Second and maybe ever more importantly, rust never promise the remedy to "nearly all bugs", the universe of bug preventable is a well-defined limited set.

Re:Rust vs. Go by yellowapple on Wednesday January 18, 2017 @09:46PM (#13432537)
I feel like there are lots of better languages to use than Go if you're just going to call into Rust for anything performance-sensitive. There are dozens (if not hundreds or even thousands) of other languages out there with C-compatible FFI and/or APIs; why use Go?
Re:Rust vs. Go by Thiez on Wednesday January 18, 2017 @05:58PM (#13431272)
Isn't calling into "C" (or Rust, in this case) expensive in Go because it seeds to switch stacks?
Re:Rust vs. Go by lobster_johnson on Wednesday January 18, 2017 @06:03PM (#13431316)
Expensive in Go, but not in Rust.
Re:Rust vs. Go by Thiez on Wednesday January 18, 2017 @06:23PM (#13431468)
I am aware, but the parent of my post suggested writing the "engine core" in Rust, and the other 99% in Go. Does using something that isn't Go for 1% of an application to do the "heavy lifting" and be "fast" really make sense when there is a significant cost that must be paid whenever moving between that core and the rest of the application? I imagine such a situation would need a lot of benchmarking to make sure that the end result is actually faster than writing the entire program in Go.
Re:Rust vs. Go by derefr on Wednesday January 18, 2017 @06:59PM (#13431685)
Imagine something like NumPy. Go code to play with numbers; Rust code to actually do matrix multiplications et al. Since the "hot loop" of such code would be in the Rust part, not in the Go part, you don't see much overhead.

Or, consider Firefox. Firefox's rendering engine will soon be Servo (Rust). I presume that its networking and its Javascript engine will eventually go the same way. Eventually, the only stuff left written in C in the Firefox codebase will be "glue code": business-policy logic that doesn't do heavy lifting, and doesn't need speed. In other words, the exact type of code where Go's "you'll be safer without this" assertion applies. Firefox as Go + Rust: why not?

Re:Rust vs. Go by lobster_johnson on Wednesday January 18, 2017 @06:39PM (#13431564)
Sorry, I thought you were asking. I agree, I don't think it makes sense.
Re:Rust vs. Go by voidlogic on Wednesday January 18, 2017 @06:41PM (#13431581)
In Go 1.8; due this month, cgo calls got half as expensive. They all ready are OK as long as you are smart about them.
Re:Rust vs. Go by strken on Wednesday January 18, 2017 @09:17PM (#13432404)
"Expensive" in this case is measured in tens/hundreds of nanoseconds, so it might be okay as long as your Rust code is long-running.