8 ms·
I never got around to use Rust, maybe I'll get some good answers here on HN, how does Rust compare with Go/Python/Java?
by thewhitetulip 11y ago
I never got around to use Rust, maybe I'll get some good answers here on HN, how does Rust compare with Go/Python/Java?
- ghjnut 11y agoTutorial's pretty quick and gets you a good idea of what they're shooting for. https://doc.rust-lang.org/book/README.html https://doc.rust-lang.org/book/README.html
- ultramancool 11y agoRust is an entirely different paradigm than Go, Python or Java... It's sort of like C++ meets modern functional lanauges like Scala.
- vvanders 11y agoThings that I really like: -No GC, purely RAII based resource management. -Awesome ownership with first-class support for move semantics. -Great functional constructs(Sum Types, Pattern Matching and map()/filter()/etc). -Compiles down to native code via LLVM.
- anp 11y agoNitpick: GC is technically optional in Rust, because you can stick pretty much anything in a reference-counted box or an atomically-reference-counted box (Rc<T> or Arc<T>). It's not the default by any means though.
- vvanders 11y agoSure, much like C/C++ could have GC by embedding Lua, Spidermonkey, etc(fun fact Epic implemented their own C++ based GC for Unreal3). It's not a forced requirement :).
- masklinn 11y agoHell, > GC is technically optional in C++, because you can stick pretty much anything in a reference-counted pointer (shared_ptr<T>).
- malkia 11y agoweek_ptr<T> - keeps a pointer for a week.
- Gankro 11y agoI really wish calendar-oriented programming had taken better hold in the 80's. It's a really elegant paradigm with great separation of concerns. Being able to shard data out into timezones with inter-timezone accesses requiring a delay equal to their clock differences completely eliminates races! Unfortunately it was pushed out by MIT's cartography-oriented zealots, and we know how well that paradigm worked out!
- tatterdemalion 11y agoI am unironically into both of these ideas.
- pjmlp 11y agoSince C++11, C++ has a standard API for GC integration.
- yarrel 11y agoOne day a student came to Moon and said: “I understand how to make a better garbage collector. We must keep a reference count of the pointers to each cons.” Moon patiently told the student the following story: “One day a student came to Moon and said: ‘I understand how to make a better garbage collector...
- mlvljr 11y ago+1 to anyone who knows the book name :)
- kzrdude 11y agoNitpick: Rust includes a GC. Box<T> is reference counted, although the reference count is always 1 until it is released by the owner, then it reaches 0. The reference counts are inferred statically for the most part. :-P
- Ericson2314 11y agoAlways inferred statically for box.
- Gankro 11y agoNo, if you conditionally move a box, there needs to be runtime checks for whether that condition occured when in it goes out of scope. (note that reassignment of a variable effectively causes the old value to go out of scope -- this may have Implications for your loops, though I sure hope you aren't making and destroying boxes in a loop!) In my experience, this is not however a significant concern.
- Ericson2314 11y agoOoops yeah forgot about https://github.com/rust-lang/rfcs/blob/master/text/0320-nonzeroing-dynamic-drop.md https://github.com/rust-lang/rfcs/blob/master/text/0320-nonz.... [To be perfectly pendantic, one could trade the drop flags for code bloat and have only a finite blow up and statically known everywhere, so its a "weak" form of dynamism.]
- Gankro 11y agoYeah I guess you could have exponentially many statically compiled paths for each combination of drop flags... but then you're just encoding your drop flags in the instruction pointer :) edit: this of course implies an easy program with 65 conditionally moved boxes that can't be encoded under your system.
- Ericson2314 11y ago
- Manishearth 11y agoOr use https://github.com/manishearth/rust-gc https://github.com/manishearth/rust-gc, https://github.com/fitzgen/rajan-bacon-cc https://github.com/fitzgen/rajan-bacon-cc
- dikaiosune 11y agoOr Spidermonkey's GC, correct? My point was more about RAII not being the only resource management strategy.
- Manishearth 11y agoYeah, Servo uses SM's GC for its javascripty things, it sort of has to. Hooking into spidermonkey to get a GC for a program where you just want a GC and not Javascript is suboptimal though. (Note that all of these GCs use RAII under the hood, but not in the simple delete-when-destructor way)
- mike_hearn 11y agoThey aren't really comparable. Rust is a lower level language that primarily competes with C++ (finally! C++ badly needs the competition). C++ is still around because it is one of the few languages that has a pay-as-you-go model to features and is not GCd, so, you can reasonably do things like write embedded software for micro-controllers, or kernels, etc. Go, Python and Java (or any JVM language) are all high level garbage collected languages that focus on developer productivity. You pay certain costs just as the price of entry, like garbage collection, and the requirement for a fairly hefty runtime. In return you get various useful features. Examples: You would not use Rust to write a large complex webapp as part of a corporate team, that spends most of its time talking to databases or message queues. The best tool for this from your list would be Java. You would not use Rust to write a small script to do system administration tasks or quickly prototyping a new idea. The best tool for this from your list would be Python. You would not use Rust to write a small, simple command line tool that nonetheless could benefit from being garbage collected. You could use Go for that (I hesitate to say it's the best tool but plenty of people use it in that way).
- abritishguy 11y agoI'm curious as to what makes you think that Java is preferable to Go for a large webapp that "spends most of its time talking to databases or message queues". I would have thought that the Go's concurrency model would give it an edge.
- baq 11y agolast time i tried to do serious work with go and mssql, i ran away screaming. maybe situation isn't that dire now (this was almost a couple of years ago), but it's hard to beat java in db connectivity. for the record, i ran to python.
- Zikes 11y agoI've used Go in a lot of database work as of late, and it's done a fine job for me. I've used it to connect to MS SQL, PostgreSQL, and Teradata. The Teradata connection was a little tricky, as nobody had written a Go/Teradata driver yet and I had to route it through Windows ODBC, but once I had that sorted out it worked just fine. I only started using Go in the last couple of years, so I don't know how different it is now from when you tried it last, but I bet you would be pleasantly surprised if you gave it another look.
- sargas 11y agoHere's my perception of Rust: It is a system's low level language (more like C or C++) that is very expressive. It's performance is compared to C++, so faster than Go/Python/Java. ---------------------------------------- In term of expressiveness, it offers: - Expression-based languages (instead of statement-based) - Has anonymous functions (lambdas) - It has a match mechanism which is powerful - Enums are enumerated data-types rather then integer types - Has traits and explicit implementation blocks for them (vs Go's implicit interface contracts) ---------------------------------------- Other than that, it also offers: - Built-in concurrency - It has a thing called the borrow checker that makes sure you're handling memory safely (this will get a little but of getting used to, but it is powerful) - Everything is private by default. You put `pub` in front of an identifier if you want it to be public - It isn't very verbose in the Java sense, but you still have to write a crap lot of code in comparison to Go and Python. The trade off is that the code is very explicit, and you get to type more in order to have zero cost abstractions at runtime - Zero cost abstraction at runtime Please correct me if any of those points are wrong/misleading, I'd love to learn more about Rust too.
- bbatha 11y ago> - Built-in concurrency This is a bit misleading, rust does not come with concurrency out of the box. The compiler is able to infer some basic properties of your program to ensure that it is 'concurrency safe'[1] any additional concurrency features are offered through libraries that mostly wrap C libraries. The std lib only comes with system threads, and some basic primitives like mutexes and channels. However, because of these features its fairly easy to build libraries that offer concurrency primitives. For example, `mio`[2] can be used for async socket programming, `rayon`[3] can be used for some parallel computation. [1] http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html http://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.ht... [2] https://crates.io/crates/mio https://crates.io/crates/mio [3] https://crates.io/crates/rayon https://crates.io/crates/rayon
- sargas 11y agoThanks for the explanation. Would you please clarify something to me? 1. So to say that a language has concurrency built-in is, in general, misleading, correct? 2. Than a language may have concurrency primitives, but the capability comes from C through the OS?
- robohamburger 11y agoAfter using rust a bit I would say that unless you requirements dictate being very frugal around things like memory allocation and speed etc.. I would not use rust to write said application. As other people have posted it seems to compete with C/C++. I am really excited about this since I think there are a lot of problems with C++ we just don't see them because there is no competitor. For example in C++ reflection and interfacing to other higher level languages is awful. I am hopefully with rust we can do better! That might really open up rust a lot of uses for rust as a language. Another area where rust is different from python and java: the rust crates in the wild still seem like a wild west of 0.x version packages that break frequently (at least for games programming). It is a great opportunity to contribute to OSS but can also be frustrating. My recommendation: if you have a pet project unix daemon or CLI tool you wanted to make try it with rust. Most of the rust standard library seems to have stabilized and is nice to use now. For complicated applications be prepared to contribute upstream fixes to crates and bring lots of patience :)
- lmm 11y agoThat's a very broad question. Rust does the things that I would say are table stakes for a decent programming language these days: decent type system (similar safety to Java) with type inference (similar conciseness to Python), a sensible approach to errors (errors are values as in Go, but since Rust is a non-joke language it doesn't need to special-case errors at the language level, they're just another type of value). Its unique thing is the semi-manual (but safe) memory management, but if you needed that then you would know you needed that, otherwise it's not terribly important to you. So it's a decent language, but there are other decent languages around these days. I tried to compare them at http://m50d.github.io/2015/09/28/when-rust-makes-sense.html http://m50d.github.io/2015/09/28/when-rust-makes-sense.html . I'd look at OCaml first, particularly given their relative maturity levels, but if you really can't stand OCaml's syntax then Rust may be worth a look.
- nindalf 11y ago> it doesn't need to special-case errors at the language level Could you explain this? A lack of explanation makes it seem flippant and is probably why your comment is greyed out.
- lmm 11y agoRust error-handling https://doc.rust-lang.org/book/error-handling.html https://doc.rust-lang.org/book/error-handling.html - Result is just an ordinary type defined in the language. Whereas go's "if err, res" stuff is special-cased - e.g. you can't use your own custom representation of error vs not.