13 ms·
I have been thinking to myself whether I should pick up Go or Rust as a new language this year. Coming from a NodeJS background, Rust looks a tad more complica
by xEnOnn 4y ago
I have been thinking to myself whether I should pick up Go or Rust as a new language this year.
Coming from a NodeJS background, Rust looks a tad more complicated but it looks cooler. There are also more job listings looking for Golang than Rust which makes me wonder if Golang might be a more rewarding investment?
What would be a good use case of Rust than Golang cannot do given its extra complexity and potentially lesser monetary reward? Any advice on which I should pick as a new language to learn?
- shiomiru 4y agoThere was a relevant discussion here just a little while ago: https://news.ycombinator.com/item?id=31976407 https://news.ycombinator.com/item?id=31976407
- azeirah 4y agoJust thinking out loud, does go compile to WASM? I often see performance critical WASM snippets written in rust, but never in Go.
- rob74 4y agoYes it does, but there are some issues, mainly the size of the compiled WASM file. But you can get around that by using TinyGo. I'm not that deep into it, but this article seems to give a good (and as far as I can see up to date) overview: https://elewis.dev/are-we-wasm-yet-part-1 https://elewis.dev/are-we-wasm-yet-part-1
- Philip-J-Fry 4y agoGo compiles to WASM but the stock compiler is pretty bad for this and your binaries are like 2MB+ in size. TinyGo is an LLVM based compiler that targets microcontrollers but also has a WASM target and that creates considerably smaller binaries, but it doesn't fully support all of the Go standard library.
- doctor_eval 4y agoTinyGo is great, I used to to program microcontrollers and there wasn’t anything I really missed, though admittedly it was a very small program.
- masklinn 4y agoGo does compile to wasm, however because wasm is what it is it has to carry around the entire runtime. This is obviously a much bigger issue for delivery over the web than it is for shuffling binaries around, or even more so creating them locally: last I’d checked, the baseline (an empty main function) for a go wasm package is about 1.3M.
- pjmlp 4y agoHardly an issue when looking at the ads crap that get download in every "modern" site.
- masklinn 4y agoSure if your use case for go wasm is ads crap knock yourself out.
- pjmlp 4y agoThat wasn't my point, ads and SPA crap available almost in every "modern" site, are several MB bigger in size than Go runtime on WASM. Ergo a a WASM Go application will be much smaller than those "modern" sites. I bet even smaller than GMail and Google Docs.
- alpaca128 4y agoSure, but I think if you see the size of ad-loaded pages as a size budget or standard for your website you're already on the path towards setting your own bad example.
- yakorevivan 4y ago
- prerok 4y agoSure it can: https://golangbot.com/webassembly-using-go/ https://golangbot.com/webassembly-using-go/ Never tried it, though :)
- devnull3 4y ago> What would be a good use case of Rust than Golang If you can afford GC in your project go for Golang else Rust.
- metadat 4y agoIf you learn Rust and become proficienct, Go will be comparably trivial.
- indiv0 4y agoAs someone with extensive experience with Rust and a teensy bit of experience in Go I can tell you that I adore Rust for every use case I’ve tried it out for *except* for network services. It works ok for low level proxies and stuff like that; but Python/Flask-level easy it is not. Meanwhile my experience with Go has been the reverse. I’ve found it acceptable for most use cases, but for network services it really stands out. Goroutines <3
- tofuahdude 4y agoCould you please expand on this a bit? What are some example services that would be better written in go vs rust?
- Animats 4y agoYes. Rust is for what you'd otherwise have to write in C++. It's overkill for web services. You have to obsess over who owns what. The compiler will catch memory safety errors, but you still have to resolve them. It's quite possible to paint yourself into a corner and have to go back and redesign something. On the other hand, if you really need to coordinate many CPUs in a complicated way, Rust has decent facilities for that. Goroutines don't have the restrictions of async that you must never block or spend too much time computing. Goroutines are preemptable. The language has memory-safe concurrency (except for maps, which is weird) and has garbage collection. So you can have parallelism without worrying too much about race conditions or leaks. Go comes with very solid libraries for most server-side web things, because they're libraries Google uses internally. Rust crates have the usual open source problem - they get to 95%-99% debugged, but the unusual cases may not work right. Go has actual paid QA people. Go has limited aims. It was created so that Google could write their internal server side stuff in something safer than C++ and faster than Python. It has a limited feature set. It's a practical tool. I write hard stuff (a multi-thread metaverse viewer) in Rust, and easy web stuff (a data logger which updates a database) in Go. Use the right tool for the job.
- zozbot234 4y ago> You have to obsess over who owns what. Most of the time you can also avoid this by just copying data using .clone(). This adds a tiny bit of overhead, which is why it isn't a default - but it'll still be comparatively very efficient. Similarly, there are facilities for shared mutation (Cell/RefCell) and for multiple owners extending the lifetime of a single piece of data (Rc/Arc). It's not that hard to assess where those might be needed, even in larger programs.
- cryptos 4y agoRust is the more elegant and powerful language. Creating a new language and repeating the "billion dollar mistake" by including null (sailing under the brand name "nil" in Go) is just crazy. Error handling is another strange thing in Go. And generics have been only introduced recently, but there is hardly any support for libraries in it (now). While Go is definitely fast enough for most scenarios, it is not the best language for low level code like drivers or kernel development. So, depending on your goals, I think Rust is the better language in general. But if your goal is to get something done fast, then Go would probably be better, since it doesn't require that much learning effort.
- lpapez 4y agoWhile Go is definitely fast enough for most scenarios, it is not the best language for low level code like drivers or kernel development. Go was never ever intended for this purpose.
- cryptos 4y agoYes, I know (although they promoted it as a "systems language", but it was not really defined what that should mean in the beginning), but it is a restriction, you don't have in Rust. Basically, Rust can do everything Go can do, but not the other way around. That _might_ help to make a decision for a language.
- stavros 4y agoTechnically, assembly can do everything Rust can do, yet that doesn't help to make a decision for a language. Ergonomics matter.
- agumonkey 4y agoIt seems to be an idiom shift. Systems means connected parts, go concurrency does just that, connecting parts through channels. But it's not `systems` as in bare metal electronic chips systems. More like IT `system`.
- mmarq 4y ago
- mihaigalos 4y agoWhat are you looking for in the 2 languages? Here are some of my thoughts: Golang * Development speed: Golang wins by far. It's closer to Python in that regard, but with strong typing. * Very nice multi-threading via Go routines and channels. Impressive semantics in simple syntax, requiring no synchronization mechanism on the user side. * Large garbage collector penalty. Rust * Complete language with build system, crate, docs hosting. * A lot more performance compared to Golang, on par with C++. * Doctests (!). * Slow to learn, slow to compile (probably not a deal-breaker, especially if you focus on microservices). Concerning what would be a good usecase for Rust vs Golang, check this out: https://discord.com/blog/why-discord-is-switching-from-go-to-rust https://discord.com/blog/why-discord-is-switching-from-go-to...
- tofuahdude 4y agoHow "large" is the garbage collector penalty? My understanding is that the Go GC is significantly more efficient than for example JS's mark/sweep approach. Apples to oranges for sure, but I am interested in better understanding how expensive the Go GC is vs Rust performance.
- masklinn 4y agoGo’s GC is not efficient, it is responsive. That is, it trades throughput (and performances, and efficiency) for small pauses and concurrency.
- mihaigalos 4y agoCheck out the discord article I posted in the original reply. If I interpret the graphs correctly, I see: Golang: * baseline 20% cpu + spikes to 35% once the GC runs. * response times of about 1ms + spikes up to 10ms. Rust: * baseline 12% cpu + flat, no spiking. * response times of 20us + flat, no spiking (!). In terms of scaling, I interpret the results in favor of Rust. My reasoning is the more you run the GC, the bigger the penalty.
- tofuahdude 4y agoJust read that article; very informative. The TLDR is that, especially during GC, P99s and response times are notably worse in Go than Rust. Makes sense.
- nbittich 4y agoI think rust is the new haskell. After spending 7 months learning it, I can say I really enjoy the language, but there's no job in it and in my opinion, they take academic decisions that make the language way more complex than it should. Also, the community is toxic. For example, generics in Go were criticized by some, praised by others. You have the feeling that you can freely share your opinion in the go community without the risk of being harassed by the rest of the community. In the rust community, just like a sect, everybody must say that everything is just perfect. Passive / aggressive attitude is something I've seen a lot in the rust community. I would suggest that if your plan is to learn C/C++ next, and you never really understood memory issues && pointers, then rust is a perfect choice at first. I'm planning to learn Go next, I don't regret learning rust, I learned lots of things with it.
- formerly_proven 4y ago> Also, the community is toxic. The Rust community has been the friendliest PL community I've seen so far.
- nbittich 4y agoJust like in any sect. As long as you agree everything is perfect, the community is the friendliest indeed.
- pkolaczk 4y agoNope, many times I submitted a question, got help instantly with a very long explanation telling why the thing I try to do makes sense and should work, but some things in the compiler or libraries haven't been stabilized or finished yet, and they were working on that. And then giving me some temporary workarounds. The community definitely acknowledges the limitations and sharp edges and listens to the users. Thanks to that attitude, Rust is way more friendly and easier to use than it was 5 years ago.
- Ygg2 4y agoThat's not fair to Rust. I think it's feature of community size and genuine interest/innovation in Rust.
- zozbot234 4y agoSince you're coming from a NodeJS background, you'll want to pick up an introductory textbook about C as well. Rust implicitly relies quite closely on the C machine model, and introductory books about Rust (such as "The Rust Programming Language") don't do a very good job of conveying the nitty-gritty details of that model to novice coders. This is a pretty nasty pitfall when trying to code in Rust, and it's important to address it early.
- vladvasiliu 4y agoI second this. I've learned Rust after having used Python, and at first I had a few "wtf" moments, things I just couldn't understand. Everything fell into place after discussing these with a friend who knows much more about the "nitty-gritty" than I do.
- doctor_eval 4y agoThis is the main reason I’d recommend that a Node programmer learn Go first. I haven’t learned Rust yet, thought I’m quite keen to do so, but I have an (ancient) background in C, C++ and 8-bit assembly. I don’t find that I really use much of that knowledge when I work in Go, even though Go is still a lot closer to the metal than Node.
- mprovost 4y agoI'm self-publishing "Rust From the Ground Up" which takes this approach: each chapter rewrites a classic Unix utility (head, cat, wc, ...) from the original BSD C source into Rust. I find for systems programming it's easier to understand how things work in C, and then teach the idiomatic way of doing it in Rust. C is pretty easy to follow along in "read-only" mode with some explanations. https://rftgu.rs/ https://rftgu.rs/
- cercatrova 4y agoInteresting, seems similar to the book Command Line Rust which also teaches you by reimplementing Unix commands, any thoughts on the differences?
- ActorNightly 4y agoLearning Rust is a good exercise in understanding memory safety. Learning it will make you understand the gotchas of what can go wrong with memory allocation, which will translate very well to coding in other languages, especially C. Just like learning Haskel is a good exercise in understanding functional programming and lazy evaluation, which again will translate very well to the code you write as you will be able to identify pattens where functional programming can be applied. However, neither language is really super applicable to general development, because there are hoops you have to jump through to write basic code where the language advantages are not really need, and other languages are much simpler and faster to develop in. Golang is much more widely used for this reason, as its compiled yet features a gc, simpler to develop in with java contains a lot of good functionality in its stdlib.
- usrusr 4y agoI think Go would typically be considered a possible substitute of one the "more VMy" languages, Rust a complement. At first glance this looks as if Rust would be more at home with polyglotism, but the typical Rust complement would be a hot performance critical part of something much bigger, and this is already deep in the realm of strategical commitment (all the not so hot parts have to buy in). Whereas Go often enters the picture in isolated one-shots and can grow from there.
- collaborative 4y agoI founf myself in your same situation a few months ago. I chose Rust and regret it Rust is a better c++. It's not appropriate for anything you wouldn't program in c++. The coding speed is slow So if you are thinking about learning a new language to program your future apps you currently code in node, choose Go
- Jyaif 4y ago> Rust is a better c++ The Rust language is a far better C++. In practice, the compile time and binary size of Rust are out of control, which makes Rust far from being a slam dunk over C++. Crossing my fingers this will change!
- hyperman1 4y agoI get the sentiment, but like to nuance it a bit. The compile time story of rust and C++ is comparable, if you use it the same way. If you use deep include hierarchies and no precompiled headers, if you start using template heavy code like boost, or if you do code generation, the C++ compile times will quickly spiral out of control. Rust does not have the include problem, but the specialization/templating idea is shared with C++, and the code generation problem has an equivalent in the macro mechanism as used by e.g. serde. In theory, you can get comparable compile times from both. Main difference is rust heavily emphasizes a programming strategy that depends on these 2, and it has a heavy cost in compile time. Meanwhile, a lot of the C++ code is still in the 'C-with-classes-and-every-vendor-creates-a-string-class' camp and while the abstraction level is lower, so is the compile time. For the binary size, C++ can hide a lot of stuff in libraries, while rust compiles it in and duplicates it for each executable. So you pay a higher fixed cost per application. As long as rust has no stable ABI, rust will stay behind at this point. But it gets better optimization opportunities as it can merge the standard library code with yours, and inter library calls are more costly so runs wins there too. Presumably it's early day for a stable ABI in rust, big wins are still made. Long term, I'd personally like to see some ABI stability in the rust world.
- zozbot234 4y ago
- snoopy_telex 4y agoI enjoy writing go a lot more then I enjoy rust. Rust is... dense. It's a lot harder for me to read code and understand what it's doing. That said, I feel that Rust is likely the winner long term. So I'm still building my rust skills, but programming personal stuff in go.
- vram22 4y ago>That said, I feel that Rust is likely the winner long term. Interesting; why do you think so?
- woile 4y agoMost of my experience is with python and js. I feel like if you have experience with python, go resembles a lot. While if you have some experience with js, rust feels like an extension (but takes time to feel comfortable). If you like arrow functions, using map, filter, etc. You will feel amazing when using rust. Those are my 2 cents. And spite of some other comments, I found writing web servers in rust okay, and I think go is also fine for web services. And with go it also feels a bit like python when using other libraries, I don't know where to start. While rust with cargo is more similar to the npm experience
- bbojan 4y agoOne drawback of Go (in my opinion) is that it has a runtime. So it's very difficult (impossible) to use it with other languages that also have a runtime. So if you learn Go, you'll never be able to use it to interoperate with e.g. your Python program to speed it up. With Rust, you could use it to replace the most time critical parts of your high-level program piece by piece. The learning curve is then much easier, and adoption can be gradual.
- prirun 4y ago> So if you learn Go, you'll never be able to use it to interoperate with e.g. your Python program to speed it up. Never done it myself, but: https://www.ardanlabs.com/blog/2020/07/extending-python-with-go.html https://www.ardanlabs.com/blog/2020/07/extending-python-with... https://github.com/go-python/gopy https://github.com/go-python/gopy
- int_19h 4y agoHaving a runtime does not, by itself, preclude interoperating with other languages that have their own runtime. Here's a project that does that for .NET and Python: http://pythonnet.github.io/ http://pythonnet.github.io/ (Note that this is not a reimplementation of Python on top of CLR, but rather a bridge between CLR and CPython.) The thing that makes FFI problematic in Go is green threads, which have their own stacks that nothing but Go understands. Thus, every FFI call has to arrange things to be what the callee expects, and you can't do async using goroutines across language boundaries (whereas callback-based solutions like promises work jsut fine).
- olalonde 4y agoI had the same reflexion about 2 years ago. Realistically, pretty much any program written in NodeJS can be ported to Go and vice versa. But not every Rust program can be ported to NodeJS/Go. It opens up a new class of software that is not typically available to NodeJS/Go developers (e.g. systems programming, embedded, writing libraries for other languages, etc.). So I went with Rust and am very happy with the decision. Despite being a systems programming language, it feels surprisingly like a high-level language and I now default to programming stuff in Rust unless there's a strong reason to use NodeJS. PS: That said, an often understated benefit of Go is that the community and job opportunities are massive in comparison to Rust (for now, at least).
- ChrisRR 4y agoIf you're looking for a new language in order to get a job, then I wouldn't be looking for either of these languages and look into something much more common like C++ given your background. I see Rust as more for people in systems programming who want improvements over C, rather than a desktop developer looking to learn something new. There's a lot of hurdles that you only really appreciate if you've come from an unsafe/low-level background
- kif 4y agoIf you want to optimize your learning experience, then learn Go first. Rust has a very steep learning curve, whereas you can pick up Go very very quickly. I learned Go by reading The Go Programming Language. It's a bit old, but a very good book nonetheless.
- oconnor663 4y agoI second this. I'm a huge Rust fan, and not really a Go fan, but if you're thinking about leaning both, it will be much faster to learn Go first. Spend a couple weeks on that, and then you'll have another data point to compare while you learn Rust. (Go also distinguishes between pointers and values, which will be a helpful concept to have under your belt when you start Rust.)
- Cthulhu_ 4y agoI have no experience with Rust myself and a good 2-3 years with Go, so my opinion here is biased but: I think Go is more suitable for general all-purpose programming, whereas Rust is more specialized; I'd pick the latter if you need to do high-quality, close-to-the-metal software, and Go for more generic software, taking the same spot that NodeJS did for you. That said, Go isn't a very "convenient" language; there's not as much magic or magic libraries that come with the language that take over big chunks of your application, and the community at large actually recommends against using libraries in favor of just using the standard library. And after a while, I... kind of agree? My HTTP API is gorilla/mux, which is only a thin layer over the standard library's HTTP server APIs (it adds routing / path matching). I started using Ent to abstract away my database, then switched to Gorm when I got annoyed at having to write so much code just to do inserts / updates and manually having to add / remove rows, but that one falls apart as soon as you have a data structure that maps to more than one level of tables deep. I mean part of my troubles with databases is probably a disconnect between wanting to store items like whole documents but mapping them onto a relational database.
- bbkane 4y agoYou might look into your database's support for JSON columns. Sometimes you can even make indices for expressions on them
- philosopher1234 4y agosqlc is very go-like, i recommend it.
- pizza234 4y ago> What would be a good use case of Rust than Golang cannot do given its extra complexity and potentially lesser monetary reward? Anything where low-level control is required. It's not clear if there are true-Rust web apps in the wild (as opposed to web apps with some services in Rust); as far as I read, Rust web programming is ugly. The market still offers few positions, largely dominated by crypto. I have the impression that it will still take many years before the field will move to Rust (where appropriate). > Any advice on which I should pick as a new language to learn? Depends on the concrete goals. If you want to make a career, Golang is the safe bet, by a very long stretch. If you want to have fun, try both, and you'll naturally find your inclination, as they have a radically different flavor.
- kouteiheika 4y ago> Anything where low-level control is required. It's not clear if there are true-Rust web apps in the wild (as opposed to web apps with some services in Rust); as far as I read, Rust web programming is ugly. There are. I run one. Written in pure Rust. 160k lines of Rust code in total, serving over 3 million HTTP requests per month. Best choice I've ever made. Rust especially shines when you need to maintain a big project over a long period of time. People often say that Go is much more productive than Rust, and in most cases that is true, but as the size of your project increases and your expertise in the language increases this relationship inverts, and Rust starts to be much more productive. Pick a right tool for the job.
- gg2222 4y agoWhat Rust web libraries/frameworks do you use and recommend? How long does your Rust project take to compile?
- memorable 4y agoI'm not the OP, but I liked Warp[0] the most. Actix Web is cool, but looks ugly and hard to use. Rocket doesn't even work. And Tide is lean and clean, but its examples and codes aren't as well-made as Warp. [0]: https://github.com/seanmonstar/warp https://github.com/seanmonstar/warp
- xEnOnn 4y agoI figured I should have given some context to my question on deciding to learn either Rust or Go. One of the reasons I started thinking which language to pick is when I started diving into web3 development. It seems like there is a trend into either using Go or Rust or both in some of the ecosystems. Think Tendermint, Cosmwasm, Solana, etc. While it makes sense to just learn both languages, I don’t think I have the mental capacity to learn both together quickly. It might work better to learn the one that has the most potential in the long run based on the trend.
- mmgutz 4y agoFor someone writing node apps, Go is a better fit. Go is much simpler than Typescript and almost performs as well as Rust. The reality is most Rust apps written by average Rust programmers do not noticeably outperform Go apps. Getting Rust to outperform Go requires a high level of proficiency in Rust. The effort vs reward definitely favors Go for node type of apps.
- risyachka 4y agoFor probably 99% of cases, Go will be a better fit as it is noticeably easier to learn and will require less time to do the task. Unless you need those extra nanoseconds of performance or super low-level features, Go will be a much better choice. In the end, they are just tools, and you need to choose them based on your needs, not language features.
- greenmana 4y agoI'd say it's also a question of team size and organization. Are you a singular developer, or in a large team, writing enterprise software that should be easy to pick up for someone reading the code 10 years later etc.
- Fiahil 4y ago> Coming from a NodeJS background, Rust looks a tad more complicated but it looks cooler. Here, Rust has officially climbed past NodeJS on the "cool" ladder. Let's rejoice, and welcome our fellow programmers into our communities !
- spicysugar 4y agoI personally feel rust is advertised more as safer and faster rather than as a practical yet harder alternative to C or C++. Although Go as a systems programming language is misleading, it's not something that is as heavily discussed about. In the long run Rust's complexity will hurt newcomers(new to programming) while it will be a blessing for seasoned c and c++ devs. If all programming languages were tools, rust would be a very very specific tool which makes a lot of sense for a specific case. If nodejs and golang are tools, choosing one over another is easier as you can do same things in both easily with small effort. But you cannot rewrite all rust programs in nodejs or golang. Finally you need to ask if rust is really worth picking over golang/nodejs for things that can be easily done in nodejs/golang. Rust is not for people who think is rust for them. Arguments like some implementations are more elegant in some other language can always be brought up as arguments. They should only be taken into account when you run out of options to compare because they are exaggerated and subjective most of the times. For example(exaggerated) screaming why go doesn't have a borrower checker like rust makes no sense because go is garbage collected. For many people seeing such absence of features equate to lack of features in a programming language leading to more boilerplate or other downsides which is not necessarily true.
- gwbas1c 4y agoI think it's worth spending a few weekends with Rust, even if it's just to expose you to some of the concepts in the language. Beyond things like borrow-checking; the language introduces a LOT of concepts that are quite foreign. Exposing yourself to them is good; because I expect that future languages will borrow heavily from Rust.
- deleted 4y ago[deleted]
- cultofmetatron 4y agoyou'll grow more as a developer from rust. Rust will force you to think about things like memory management, safety etc. additionally, it has a rich set of abstractions. rust also has better interop with c and c++. In the long run, you're better off learning rust. You'll encounter a brutal learning curve but once you know it, you'll find yourself able to do very powerful things with ease. especially once you internalize the borrow checker. Go is a great language for the short term but I don't feel like it brings Anything unique or interesting to the profession. its only real advantage is that its quick to learn but there isn't much substance. Its a great language if you're the type of person who doesn't mind copying large reams of code to change a few lines for a new purpose.
- anon291 4y agoI worked in Haskell for many years. It is an absolute myth that rare languages command less salary. Remember the more popular the language, the more supply, hence less pay.