Rust vs Go

How do they compare?

Other urls found in this thread:

github.com/golang/dep
youtube.com/watch?v=Lj1GppqNr8c
github.com/apple/swift
twitter.com/SFWRedditGifs

well one tries to be C++ and fails and the other tries to be C and fails

Pretty sure half of Rust's motivation comes from unsafe stuff C++ does. I wouldn't call that trying to be C++.
>oh but it's also very performance oriented and it has objects

yes but it's also very performance oriented and it has objects

But it has bunch of stuff from functional languages too.

yes but the elephant in the room which you're ignoring right here is that it's trying to be C++ and fails (because it's also very performance oriented and it has objects)

...

Go makes many trade-offs for simplicity and clear implementation over performance (it's still really fast when compared to Python/Ruby/insert anything not know for being fast).

Go's toolchain is portable. It has it's own compiler backend (not unusual, D also has it's own backend with better debugging and faster compilations, but unlike D, Go's llvm and gcc backends aren't popular and lack some memory optimizations (escape analysis)). New versions are in Go itself, but 1.4 is maintained for bootstrapping and written in ANSI C and Plan 9 C toolchain, which makes it freakingly portable on all sorts of architectures and OSs. After ANSI C it might be the most ported language.
Rust lacks here a bit, only llvm backend. While llvm is ported to quite a bit platforms, the rest of toolchain isn't. You have full llvm+rustc+cargo+rustup on pretty much only on amd64-{windows,linux,mac} and tier 2 freebsd. But can cross-compile for all relevant platforms.

Go is simpler to program in. You have many quality implementations in stdlib and official /x/ packages. Base language offers CSP concurrency primitives - lightweight threads, channels, select and other tools to create logics and syncing, async package for traditional atomic operations and locks. CSP isn't the only concurrency approach, Go forces it to you. Rob Pike seems to be obsessed with it.
Rust has many things fragmented to external packages, you can't write program without downloading something. Regarding concurrency, there is Tokio framework which uses Futures (Promises is some other languages) and event loops for them. All of it seems chaotic and documentation is crap (some examples don't even compile). Crates.io is terrible website and serves poorly as catalog.

Go's approach to code reuse is again simplistic, you have structs and variables for state and interfaces for behavior. There is nearly no functional programming of abstractions like iterators. It's purely procedural. Rust is a lot like JavaScript done right.

>unsafe stuff C++ does

>this compiles without warnings or errors
std::vector v;
v.push_back("first string");
auto first = v.begin();
v.push_back("second string");
std::cout

>llvm is ported to quite a bit platforms
Yeah also LLVM (the software) doesn't really work on most platforms it's ported to even if backends somewhat work. In fact it's only truly reliable on Apple systems.

>Rust is for people who can't read
Explains a lot.

You probably don't even know what's wrong with that code.

>be a rustoddler
>make retarded assumptions
>be retarded
The narrative fits so far.

>he actually doesn't know
>he's shitposting to buy time for googling the answer

>compiles without warnings or errors
???
vector.cpp:1:6: error: ‘vector’ in namespace ‘std’ does not name a template type
std::vector v;
^~~~~~
vector.cpp:2:1: error: ‘v’ does not name a type
v.push_back("first string");
^
vector.cpp:3:14: error: ‘v’ was not declared in this scope
auto first = v.begin();
^
vector.cpp:4:1: error: ‘v’ does not name a type
v.push_back("second string");
^
vector.cpp:5:6: error: ‘cout’ in namespace ‘std’ does not name a type
std::cout

not him. is the problem that the pointer to the first element is accessed after the vector has been updated?

Rustoddler btfo

I only just noticed that it says treespirit and not treespirit

Yeah, all pointers are considered invalid after you modify a vector and C++ can't express that in its type system.

lmao

Iterator invalidation on resizing. It's powerful.

I guess that gives more flexibility to the collection to be able to rearrange itself

...

Rust doesn't prevent vectors from rearranging themselves. It prevents you from holding a reference to an element while you're modifying the vector.

>treespirit
>treespirit
They're the same word?

>wah what are headers
retard.c: In function ‘main’:
retard.c:2:2: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
printf("Hello, world!\n");
^~~~~~
retard.c:2:2: warning: incompatible implicit declaration of built-in function ‘printf’
retard.c:2:2: note: include ‘’ or provide a declaration of ‘printf’

fuck. the second one should be freespirit

>an implementation contract means you can't express it in the type system

pt2 since twitterchan doesn't like long posts
Rust is strongly typed with full blown generics. So many things are traits in Rust - Clone/Copy signals that data are safe to clone, Sync/Send for concurrent use in other threads e.g. It's doesn't provide definitive answers like Go does, but at least it's not legacy bandwagon C++ style.
Both don't have Objects. I'm pretty sure Rust can emulate all the embedding of structs that Go can do, but again it's simpler in Go but with less features.

Go has less control over that goes to stack and what on heap. This decides compiler - uses escape analysis to decide if data leaves function scope. It's simple and efficient if you don't mind GC. Rust's ownership-borrowing model is cleaner and more efficient RAII from C++. It tracks lifetimes and scopes of data and automatically places destructor. Go's GC is quite fast and concurrent. When you need to avoid allocations on critical paths, you still need to use tricks in both languages. No GC is only advantage when you care for rendering every frame in time and shit.

Rust toolchain is just weird. The whole thing is over 5 million loc. The Cargo package manager tries to do everything - some plugin management, chaotic and not easy to use build tool and other weird stuff, while still needs toolchain manager rustup that for weird reasons handles docs and code completion plugins. And they are both HUGE.

And I don't get metaprogramming
>brainlet
yes

What is that even supposed to mean?
It's a contract that's impossible to express in the type system.

>Rust toolchain is just weird. The whole thing is over 5 million loc.
The compiler is 100k loc, where did you get the remaining 4.9 million from?

>the interface of std library containers makes it so that dereferencing invalid iterators is UB
>this means iterator invalidation is impossible to express in the type system
Did you also know you can write immutable variables in C++?

We are clearly not on the same page here.
Rust doesn't let you keep reference to a vector element after the vector has been modified.
That's a compile-type error. It's not undefined behaviour. It doesn't even compile.

You can't do that in C++.

i think id be more fair to compare rust with javascript as theyre mozillas answer to that question
go is fun tho

Yes, it's quite obvious we're not. I've tried explained why the std::vector type allows that and you keep repeating yourself about how it's because the C++ type system doesn't allow it. In fact it is trivial to make the same behavior happen in Rust. Let's look at it another way:
>You can't do that in C++.
What makes you believe that?

>I've tried explained why the std::vector type allows that
I must have missed that. All I saw was nonsensical greentext.

>What makes you believe that?
Everything I know about C++ goes against what I believe you are trying to suggest. I will give you the benefit of doubt and assume that we are not actually talking about the same thing.
In that case please explain what you mean, preferably with an example.

>Rust
Tries to replace C/C++ and fails
>Go
Tries to be easy to use with dead-simple concurrency and succeeds

Go has a lot of weird faults but they're things it never set out to do.

That's because you don't use any static analyzer. I think even clang's sub-par scan-build catches this.

They both try to be safer versions of the C that they're inspired by.
Go succeeds due to Google's aggressive desire for a language that works for the retarded googlers. Rust is being pulled in various different directions and stalling.

Go was stylistically designed after C, it was never meant to compete with it. It was meant to be an easy to write, easy to write, procedural language with strong concurrency.
Which it is.
Go's main downfalls are its package management (fucking retarded), its dev environment (FUCKING retarded) and "muh generics".

>easy to write, easy to read
hurp durp

cargo: 58k rust
jemalloc: 20k C
rustup: 17k rust
liblibc: 40k rust
rustc+stdlib: 530k rust, 10k C/C++
llvm: 500k C++, 230k assembly, 140k C
ok cutted all comments and counting actual code it's "only" 1.5 million

I actually tried a similar example with a bunch of freely available static analyzers. I think I tried clang too.
I was surprised when none of them caught it because I thought it was a very basic error.

Go is a language designed to solve a problem, Rust is language looking to solve a problem. Go succeeds because it was designed for a problem, which happens to be a common one. Memory safety and data races are not huge problems in industry that they require a whole new language to fix them.

>jemalloc: 20k C
god damn. Why is malloc / free so big?

>it was never meant to compete with it
Not for the public, but it was meant to be a direct substitute for the workforce @ google. Just so happens a lot of people outside Google want that too.
That's a very good way of putting it.

> it was meant to be a direct substitute for the workforce @ google
Again, no, it literally wasn't. You're misinterpreted rob pike's quotes on "we needed a simple language" by such an enormous margin.
It was meant to be comfortable to work in for people coming out of academia, which meant they mostly only knew basic Java and C. It was designed to be almost impossible to make hard to read, and it really does succeed in that respect.

It was never, ever, not for a second meant to replace or compete with C. It was just meant to be easy to understand coming from a C background.

>dev environment
what's that?
>pkg management
it's coming, hope it won't suck github.com/golang/dep
GOPATH is comfy for linking, easy to work with since it's just env variable
Go comes from Pike's initiative and obsession. He worked before on concurrency in Plan 9 and made 3 or 4 languages with similar idea before (Alef, Limbo, Newsqueak and that Plan 9 C stuff). Imho he just managed to sell it to Google managers.

>Memory safety and data races are not huge problems in industry
>meanwhile every major browser is using sandboxing because they are sure that their C++ code is broken and vulnerable

>I must have missed that
So for the third time, the reason is because checking that iterators for standard library containers are not invalid before use is part of their contracts, not their type. So the flaw is with std::vector, not the type system.
>please explain what you mean, preferably with an example
Better designed proxy objects. More practical, there is the tagged friend function but apparently it triggers the committee so they're looking for way to forbid it. See youtube.com/watch?v=Lj1GppqNr8c for a POC of that where modification of the vector is impossible while you hold an iterator. It's not the same error but ultimately it prevents the same bug.
Also more theoretical, you can do any "compile-time" checking you want in C++ (this also applies to Rust), their type systems are (accidentally) Turing complete.
In short the problem is retro-fitting safety inside the standard library, not having an unfit type system.
Memory allocation is a highly non-trivial problem.

simplistic allocator ~500 loc
optimized for performance and speed 20k loc
also it's C so it needs to implement every primitive by itself

Again, no, it literally was. You're being far too generous with your interpretation of his quote. Go back and read it. You'll find yourself agreeing with me.
Stop bringing competition back into it, a substitution isn't a competition by any means.

One is a shitty basic Google language, and the other is the future of programming.

Is there even a legit reason to use pointers with stl vectors?

>dev environment
The whole GOHOME GOROOT nonsense, it's fucking infuriating.

>package management
Everything has to be on github or gitlab or something insane, and you can't ever make your own local packages for private projects without using vendor crazy bullshit. It's the most insane system I've ever seen.

>no, it literally was
Go ahead and show me where it states it was meant to be a replacement or competitor for C. It was meant to be an easy to use C-like language.

He said pointer but it's actually iterators. Pointers too, of course.

>unsafe
You fell for the meme it seems.

>Rust glues together a static analyser to its compiler
>Complains that retarded ways of using C++ that invalidates iterators aren't caught by compiler
>Haha I told you Rust is safer!
Fucking Rust monkeys

>must be on github or gitlab
no it doesn't, maybe you are using it wrong
it's literally imported by url relative go GOPATH

samefag

Rust homosexual detected. No shit it's the same fag, I replied too quickly to the first post.

>imported by url
99.9999% of the time which means it comes from the master branch of a repo.
Which means any changes that get pushed that happen to slightly break the package in any way fucks everybody up using it on recompile. It's the npm left-pad fiasco just begging to happen all over again

Ok so i was really disappointed when i read that, so much so that i didn't believe you and checked for myself. And oh look, it's another episode of lying Rust shills. Look, i'm the last person who would defend C++ when it comes to safety, but you should know C++ before criticizing it. Rust is cool language, no need to lie about C++ tooling.
This. Though the tooling has come very far when it comes to shape analysis so we might be able to enjoy some cool tools for C in the next few years (forest automata are cool).

coroutine guy spotted

What the fuck is your screen even supposed to demonstrate?

Oh and i just noticed, i didn't pass std to clang. Nevertheless, after passing right arguments, scan-build indeed spots the error.

Well your screen just shows the part wher you blindly copy/pasted the code so of course itdoesn't build. May you show the output?

>means it comes from the master branch of a repo
It comes from your local copy which you have control over. You can change GOPATH according your needs, e.g. for project's build script to use those versions saved in project's directory. With godep you can automate the version locking by config file.

>part of their contracts, not their type
That's my entire point.

>emulating rust's borrow checker in C++
That's a horrible hack that abuses lambdas and macros and still requires inordinate amounts of new syntax. I'd hardly call that a feature of the type system.
There's definitely some runtime overhead too.

I don't know if the first part of the post is supposed to be a joke.

>That's my entire point.
Well your entire point is that you can write unsafe code? Fucking congrats, genius. I wonder which other languages have that.
>There's definitely some runtime overhead too.
Now you're either being dumb or of critically bad faith. It checks at compile time whether it's correct, if it's not it doesn't build. If runtime overhead in release mode concerns you that much, you know NDEBUG exists right? Actually I honestly think you don't, most of the shit you've said about C++ has been beyond ignorant-tier.

>static type verification
>not a part of the type system
The eternal Rustoddler strikes again!

The point is that Rust prevents you from making a whole class of mistakes, unlike C++.

>It checks at compile time whether it's correct, if it's not it doesn't build
I checked the video again and there actually don't seem to be any breaking syntax changes. You could probably define another set of macros that rewrite the expressions to normal C++ in release mode.
However I also noticed another thing. It doesn't actually prevent the error from You need to manually specify which object a reference is tied to when you borrow it. This again puts the burden of the contract on the programmer.
And guess what, it needs to be written on the caller's side so you can't hide it in the type itself.

>Rust prevents you from making a whole class of mistakes
And what do you think this is? Are you going selective on what is a mistake and what isn't, now? Rust also prevents you from making a whole class of valid programs, which makes it a non-language.
>hide it in the type itself
It's not hidden, it's explicit, and it's only because it's std::vector. It's in the type either way since it fails type checking. Regarding annotation, guess what, the language you're shilling requires type annotation to work too (or do you also not know this language?). This is better since it makes the type checking decidable. For the last time, the fact you have to write it is a limitation from std::vector, not the type system. I'm done writing here since I feel like I'm repeating myself too much.

>And what do you think this is?
A lot of things but this specific example is about dangling references.

>Rust also prevents you from making a whole class of valid programs, which makes it a non-language.
unsafe {}

>the language you're shilling requires type annotation to work too
Those type annotations are in the definition of the type. If you're just using the type you don't have to write any.

>This is better since it makes the type checking decidable
Safe should be the default.

>the fact you have to write it is a limitation from std::vector, not the type system
You can't use those macros to write a method that returns a borrowed reference. You need to handle the borrowing yourself correctly every time you use a function that returns a reference.
This isn't any better than just being aware of the contract and writing normal C++.

Why do these keep being compared? They have very little in common.

Internally, does v.begin() always point to the first item in the vector? Or does it point to the first element in the vector at the moment it was called?

why the fuck are you retards still using such low level languages in 2017? just fucking use Java or C# you fucking mongoloids

Rust is targeting systems programmers and is going well enough but many of criticisms on here are accurate.
I would add that the syntax has the feel of C++ verbosity.

I will make an unusual recommendation and suggest that those looking at Rust instead start to look at Swift. Besides a having a large base programmers, the syntax is cleaner and is going to add Rust style memory ownership.
Swift is competitive with C++ on many tasks in terms of speed. There are a few where swift is much slower but that will change.

Swift is beginning to add the memory ownership model in Swift 4 and will start seriously implementing ownership in Swift 5 when the ABI finally settles down.

>Macintosh exclusive

>hurr durr im poor and better language sucks cause its not free

ramakrishna my dude

It can be used on Mac and Linux:

github.com/apple/swift

Since the ABI hasn't really settled yet, Swift can't be considered as a seriously language for non-iOS/Mac development. It may be a few more years until it's usable for general projects.

They both made to solve problems that were already solved by Object Pascal/Delphi over 15 years ago.

T. JVM-let

Delphi is comfy.

I use Delphi at work and really, no.
What it has over Rust: faster compilation times and easy, native GUI development.
Otherwise in 2017 it's an antiquated language with an antiquated IDE that offers nothing special on parallelism, safety, generics, or anything really.
I don't even understand why you'd think of posting Delphi in this thread.

...

Give me a tl;dr in safety in Delphi

Go is for python for C. Dumbed down for retards. Rust is a good language. I like. Thx

THIS THIS THIS THIS THIS
GO FUCKING PATH DESTORYS ME
WHOS RETARDED IDEA WAS THIS!? WHY CANT IT BE NORMAL!?

This is the reason I didn't get more into Go, that path shit is retarded, I don't want my packages to all go there. That and how it ENFORCES a specific brace style. If you don't put braces where THEY want you too its a compile error!?

Well there's not really anything to safey in Delphi.
Either you have pointers to things and it's like in C, you have to allocate and free things in try/finally blocks.
Either you have plain, basic reference counting. That's not used at my workplace so I don't know much about it.

I'd like to start this by saying that I don't get all of the terms being thrown around in support of Rust and Go on here, especially with regard to concurrency, My programming experience is limited to embedded systems in C and some Ada. Ada struck me as a very safe language and I liked working in it. What does Rust have that make it a better choice than Ada? Is Ada just old and out of fashion?

The moment it was called. If the vector needs to reallocate internally, then that iterator is invalidated.

They're both programming languages. That's all they have in common.
Go is easy to learn and simple to use, but lacks proper abstractions. Rust is the opposite.

>Memory allocation is a highly non-trivial problem.

Not really. The early versions of UNIX had them and they fitted into a 64 kilobyte address space.

Modern, high performance allocation can be non trivial though.

Well Go has the most fucking retarded syntax and is autistically strict with some things and really loose with others.
That being said though, lots of server stuff is reaally short to implement in it

Another brainlet failed to understand how GOPATH works. It's so fucking simple, you probably just didn't try.
>enforces specific style
Stop being snowflake and use gofmt, it's shipped with the language.