News for hackers. Stuff that matters.
Re:How I went about learning Rust by xEnOnn on Friday July 15, 2022 @01:51AM (#32105009)
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?

Re:How I went about learning Rust by cryptos on Friday July 15, 2022 @02:06AM (#32105098)
Rust 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.

Re:How I went about learning Rust by mmarq on Friday July 15, 2022 @04:01AM (#32105853)
> Creating a new language and repeating the "billion dollar mistake" by including null (sailing under the brand name "nil" in Go) is just crazy.

You forgot pointers used to represent nullables.

Re:How I went about learning Rust by lpapez on Friday July 15, 2022 @02:52AM (#32105395)
While 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.

Re:How I went about learning Rust by cryptos on Friday July 15, 2022 @04:10AM (#32105901)
Yes, 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.
Re:How I went about learning Rust by stavros on Friday July 15, 2022 @05:38AM (#32106366)
Technically, assembly can do everything Rust can do, yet that doesn't help to make a decision for a language. Ergonomics matter.
Re:How I went about learning Rust by agumonkey on Friday July 15, 2022 @05:50AM (#32106432)
It 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`.
Re:How I went about learning Rust by nailer on Friday July 15, 2022 @05:13AM (#32106259)
> Creating a new language and repeating the "billion dollar mistake" by including null (sailing under the brand name "nil" in Go) is just crazy.

Can you explain? What do I set ‘score’ to when someone hasn’t sat the test yet?

Re:How I went about learning Rust by brobinson on Friday July 15, 2022 @05:25AM (#32106314)
Read about sum types. They exist in Haskell, Rust, OCaml, Typescript, Swift, Kotlin, etc. You are likely only familiar with product types without knowing they're called product types. (Cartesian product)

You can have 100% type-safe, guaranteed at compile time code without null that can still represent the absence of data. Once you've used sum types, you feel clumsy when using Javascript, Python, Go, Ruby, C, C++, etc. especially when refactoring. Nullness infects your data model and always comes out of nowhere in production and ruins your day.

Re:How I went about learning Rust by nicoburns on Friday July 15, 2022 @06:53AM (#32106817)
Arguably dynamic languages have sum types: every variable is one big sum type with the variants being every other type! I suspect the lack of sum types in many static languages are partially responsible for the popularity of dynamic ones.
Re:How I went about learning Rust by kortex on Friday July 15, 2022 @12:02PM (#32109505)
> I suspect the lack of sum types in many static languages are partially responsible for the popularity of dynamic ones.

I can totally see this. I started writing a small cli tool in Go, and despite knowing way less Rust, I switched to it and was able to make a lot better progress at first due to pattern matching and result types. It was just so much easier/more ergonomic to write a simple parser.

The Go code was a mishmash of ugly structs and tons of null checking and special casing.

Re:How I went about learning Rust by estebank on Friday July 15, 2022 @11:19PM (#32114949)
I would say that traits are a better analogy for dynamic types, but at the same time you can think of enums as closed sets and traits as open sets, so they are different ways of encoding sets of possible structure and functionality, more alike in what they provide than it initially seems.
Re:How I went about learning Rust by int_19h on Friday July 15, 2022 @04:30PM (#32112441)
Some statically typed languages have union types that are extensible in a similar fashion; e.g. in OCaml:

https://v2.ocaml.org/manual/polyvariant.html

Re:How I went about learning Rust by davidatbu on Friday July 15, 2022 @08:55AM (#32107628)
Very interesting perspective!
Re:How I went about learning Rust by davidatbu on Friday July 15, 2022 @05:51AM (#32106437)
To be fair to Python, the static typing doesn't have the billion dollar mistake (you have explicitly say `Optional[int]`, for eg).
Re:How I went about learning Rust by nailer on Friday July 15, 2022 @07:21AM (#32106977)
https://old.lispcast.com/what-are-product-and-sum-types/

That was easy to understand.

> You can have 100% type-safe, guaranteed at compile time code without null that can still represent the absence of data.

If it's a single score, I'd still want to use null / int. There no invalid states being represented, anything else is still unnecessary complexity.

> Nullness infects your data model and always comes out of nowhere in production and ruins your day.

A TS example: trying to do anything with 'score' where score is `null | number`, would be caught be the compiler.

Re:How I went about learning Rust by brobinson on Friday July 15, 2022 @07:57AM (#32107179)
>If it's a single score, I'd still want to use null / int.

In your example, you still have to manually check if there's a value every time, but this is not compiler-enforced. Should you forget, you will get a runtime crash at some point (likely in production at a critical time) with some kind of arithmetic error. This wouldn't be possible with a simple sum type.

Also, a sum type with units of Score(Int) and NoScore won't allow assignments of any other "null" instances. Null in one spot is interchangeable with null in any other spot, and this can lead to bugs and runtime crashes. Null should be avoided when possible.

Re:How I went about learning Rust by nailer on Friday July 15, 2022 @11:18AM (#32109033)
The compiler would enforce Number-ness every time I try and run a function that takes a number, right?

Wouldn’t I still have to check for NoScore?

> a sum type with units of Score(Int) and NoScore won't allow assignments of any other "null" instances.

I get this part - I wouldn’t be able to assign ‘NewBornBaby’ (my name null) to ‘NoScore’ (my score null)

Re:How I went about learning Rust by groby_b on Friday July 15, 2022 @12:41PM (#32110036)
> The compiler would enforce Number-ness every time I try and run a function that takes a number, right?

> Wouldn’t I still have to check for NoScore?

No, because you differentiate between the sum type (e.g. Maybe in Haskell) and the number type at compile time. It's a small distinction - there will still be one or two places where you ask "is this a Maybe-score, or a Just-Score, or a No-Score", but the upside is that in all places you are very clear if a No-Score is possible, and you can't confuse the value with the error signal.

I.e. if you pass maybe-scores to something that computes the mean, you'll get a compiler error. The writer of the mean function doesn't need to care you've overloaded an error value onto your numbers.

The compiler support is the important part. Languages like C/C++ know sum-types just fine. They usually surface as sentinel values (NULL for ptrs, -1 for ints, etc) or unions with type fields. The stdlib offers it as std::optional<T>. As you progress along that spectrum, you get increasing compiler support there, as well.

One could even argue that sentinel values are a slightly better choice than Go's pairs, because they are closer to being sum-types than the strict product type that is go's (result, error) tuple - at least sentinels can't be simultaneously carrying a valid value and an error.

Re:How I went about learning Rust by nailer on Friday July 15, 2022 @02:16PM (#32111188)
> I.e. if you pass maybe-scores to something that computes the mean, you'll get a compiler error. The writer of the mean function doesn't need to care you've overloaded an error value onto your numbers.

If I pass a null into something that calculates an average, taking numbers, the TS compiler will complain now. The writer of mean() (assuming mean() is typed) doesn’t have to know anything about my code.

Re:How I went about learning Rust by groby_b on Friday July 15, 2022 @05:48PM (#32113167)
This only works for non-sentinels. I.e. if "-1" happens to be the value indicating NoScore, I don't think the TS compiler can catch that?
Re:How I went about learning Rust by nailer on Sunday July 17, 2022 @01:07PM (#32128684)
Nobody is discussing using a magic number for null, nor is that an accepted practice in TS.
Re:How I went about learning Rust by brobinson on Friday July 15, 2022 @11:53AM (#32109403)
>Wouldn’t I still have to check for NoScore?

That's right, and the compiler will reject programs where you don't do this. It's a set of safety rails for your code. You pay a dev-/compile-time cost in exchange for your programs not exploding at runtime.

Re:How I went about learning Rust by nailer on Friday July 15, 2022 @02:13PM (#32111158)
Yes but that’s no less work than checking for null in TypeScript. The parent said:

> In your example, you still have to manually check if there's a value every time, but this is not compiler-enforced.

Re:How I went about learning Rust by brobinson on Saturday July 16, 2022 @12:43AM (#32115288)
Sure, it's the same amount of work, but you're forced to do it and the compiler will be able to reject invalid programs. In languages that allow null (including TS, it doesn't 100% enforce the stuff that Haskell, etc. does), you can skip that check, saving some work I suppose, at the risk of your code exploding at runtime. Having stack traces which jump across 50,000 lines of code because someone forgot to check for null somewhere sucks a lot.
Re:How I went about learning Rust by nailer on Sunday July 17, 2022 @01:08PM (#32128691)
TS wouldn’t let you skip that check though.
Re:How I went about learning Rust by davidatbu on Friday July 15, 2022 @05:17AM (#32106280)
The Billion Dollar Mistake refers to the fact that things that are not explicitly marked as "nullable" can be null/nil.

In rust, you would annotate score as `Option<u32>` (`u32` is one of Rust's integer types), and then you would set the score of someone who hasn't sat the test yet as `None`, and someone who got a 100 on the test as `Some(100)`.

Re:How I went about learning Rust by tialaramex on Friday July 15, 2022 @12:49PM (#32110131)
Also, because Rust is intended for writing low level software where you might very well care deeply about how big this type is:

Rust has NonZero versions of the unsigned types, so NonZeroU32 is the same size as a u32, four bytes with an unsigned integer in it, except it is never zero.

Option<NonZeroU32> promises to be exactly the same size as u32 was. Rust calls the space left by the unused zero value a "niche" and that's the perfect size of niche for None.

As a result you get the same machine code you'd have for a "normal" 32-bit unsigned integer with zero used as a sentinel value, but because Rust knows None isn't an integer, when you mistakenly try to add None to sixteen in some code deep in the software having forgotten to check for the sentinel you get a compile error, not a mysterious bug report from a customer where somehow it got 16 which was supposed to be impossible.

When a maintenance programmer ten years later decides actually zero is a possible value for this parameter as well as "None", there's a NonZeroU32, they swap it for u32, and the program works just fine - but because there's no niche left in u32 the type is now bigger.

Re:How I went about learning Rust by nailer on Friday July 15, 2022 @06:14AM (#32106564)
Oh yeah, allowing values to be nullable by default is bad, that's totally different than just 'including null'. I thought they meant including null in the language!

> you would set the score of someone who hasn't sat the test yet as `None`

Yep that's what I expected. Emoji thumbs up.

Re:How I went about learning Rust by dannymi on Friday July 15, 2022 @07:30AM (#32107023)
>Oh yeah, allowing values to be nullable by default is bad, that's totally different than just 'including null'.

In Rust (and Haskell and OCaml for that matter), there is no built-in null keyword. Option is just an enum in the library that happens to have a variant called None. So it's technically Option::None and Option::Some(x). But, really, it could be Quux and Quux::Bla and Quux::Boo(x) instead--without any language changes.

That is vastly better that what IntelliJ does for Java with their weird @NonNull annotations on references--which technically still can be the null. null is still a keyword there, and null is somehow a member of every reference type (but not of the other types--how arbitrary).

And C# has a null keyword, and the rules for type autoconverting it are complicated, and some things you just aren't allowed to do with null (even though they should be possible according to the rules) because then you'd see what mess they made there (you'd otherwise be able to figure out what the type of null is--and there's no "the" type there. null is basically still a member of every type. And that is bad).

So even the language used in "allowing values to be nullable by default" is insinuating a bad idea. Nullability is not necessarily a property that needs to exist on values in the first place (as far as the programming language is concerned).

Re:How I went about learning Rust by int_19h on Friday July 15, 2022 @04:33PM (#32112490)
For all practical purposes, in C# with nullability checks enabled, null is not a member of every type anymore: T? includes null, while T does not.
Re:How I went about learning Rust by valbaca on Friday July 15, 2022 @02:21PM (#32111245)
Rust has Option which you opt-into for cases like the one you describe.

What's special is that it's not like Go/Java/JS/etc where *every* pointer/reference can be null, so you have to constantly be on guard for it.

If I give you a Thing in Rust, you know it's a Thing and can use it as a Thing. If I give you an Option<Thing> then you know that it's either a Some or None.

If I give you a Thing in Go/Java/etc well, it could b nil. Java has Optionals...but even the Optional could be null...though it's a really really bad practice if it ever is...but it's technically *allowed* by the language. Rust doesn't allow such things and enforces it at the language and compiler level.

Re:How I went about learning Rust by throwaway234232 on Friday July 15, 2022 @11:56AM (#32109431)
You can still use a null, however the point being made here is that null was failed to be included at type level.

See these for reference

* https://kotlinlang.org/docs/null-safety.html

* https://dart.dev/null-safety

* https://docs.microsoft.com/en-us/dotnet/csharp/nullable-refe...

An orthogonal approach would be using a data type such as Maybe or Option, but ergonomics depends on language.

Re:How I went about learning Rust by sfteus on Friday July 15, 2022 @11:27AM (#32109118)
I use Go at my job, and Rust in a few personal projects.

The "typical" Go nil-check would usually look something like this (no idea how code will look, apologies up front):

result, err := someFunction()

if err != nil { ...

It's nice that you're not having to litter your code with try/catch statements, or use a union type with an error value like in other languages, but the downside is that Go only checks to see whether err is used at some point (or makes you replace it with _), and it's possible to accidentally use err in a read-context and skip actually checking the value. Go won't prompt you that the error case is unhandled (in my experience)

In Rust, when you want to return a null-like value (None), you wrap it in Option<type>. To the compiler, Option<type> is a completely separate type, and it will not allow you to use it anywhere the interior type is expected until the option is unwrapped and the possible null value is handled. You'd do that like this:

var result = some_function()

match result {

  Some(x) => handle_value(x),

  None => handle_null(),
}

The compiler forces you to unwrap result into its two possible underlying types (any possible <type> or None), and handle each case, which prevents an accidental null value being passed to handle_value. Trying to pass result directly into handle_value would give you a type check error, since it's expecting a <type> but is passed an Option<type>. The compiler will also give you an error if you try to only handle the Some(x) path without providing a case for None as well, so you can't just accidentally forget to handle the null case.

(For completeness, you can also just do result.unwrap() to get the inner value and panic if it is None, which can be useful in some cases like when you know it will always be filled, and you want to fully terminate if it somehow isn't).

So in your case (assuming this is in the context of a video game), you'd make score an Option<i32> for example, then unwrap it when you needed the actual value. Generally speaking, I'd make the score returned from a saved game loading function be Option<i32> and make the actual score for the current session just an i32, then the function that handles loading a game save into the current session would handle the Option<i32> from the save file (defaulting to 0 when this is None), and we could assume that the score would be set by the time the game session is running so we don't have to constantly unwrap it within the game logic itself.

Re:How I went about learning Rust by indiv0 on Friday July 15, 2022 @02:03AM (#32105079)
As 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

Re:How I went about learning Rust by Animats on Friday July 15, 2022 @02:37AM (#32105293)
Yes. 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.

Re:How I went about learning Rust by zozbot234 on Friday July 15, 2022 @02:45AM (#32105347)
> 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.

Re:How I went about learning Rust by abiro on Friday July 15, 2022 @07:33AM (#32107035)
This big time. Rust has comparable ergonomics to high level languages once you stop trying to optimize everything and start throwing around clones liberally. And the nice thing is that if you do need to optimize something later you can trust the compiler that if it compiles, then it’s correct (barring interior mutability/unsafe).
Re:How I went about learning Rust by srer on Friday July 15, 2022 @04:03AM (#32105861)
> The language has memory-safe concurrency (except for maps, which is weird)...

My understanding is you should operate the other way around. Things aren't safe for concurrent mutation unless it's explicitly documented as safe.

> So you can have parallelism without worrying too much about race conditions or leaks.

You might not worry, but I find these the two easiest classes of Go bug to find when entering new codebases ;).

Still, I agree Go is easier to get a web service up and running with.

Re:How I went about learning Rust by Gwypaas on Friday July 15, 2022 @04:52AM (#32106164)
Regarding concurrency and Go, it's truly an awful language from the view of concurrency when coming from Rust. It's a loaded footgun where you have to keep tons implicit details in your mind to get it right.

https://eng.uber.com/data-race-patterns-in-go/

Re:How I went about learning Rust by BreakfastB0b on Friday July 15, 2022 @03:38AM (#32105707)
Minor nitpick but goroutines are absolutely not preemptable, they’re cooperative. The go compiler regularly sticks in yield statements around IO, and certain function calls, but you absolutely can starve the runtime by running a number of goroutines equal to the number of cores doing heavy computation, just like Node.JS’s event loop.
Re:How I went about learning Rust by foldr on Friday July 15, 2022 @03:50AM (#32105788)
This changed in Go 1.14 on most platforms: https://go.dev/doc/go1.14#runtime
Re:How I went about learning Rust by BreakfastB0b on Friday July 15, 2022 @05:45AM (#32106407)
TIL
Re:How I went about learning Rust by thewarrior on Friday July 15, 2022 @03:28AM (#32105647)
Noob question - What does go lack that makes it hard to write your multi threaded meta verse viewer
Re:How I went about learning Rust by masklinn on Saturday July 16, 2022 @04:08AM (#32116119)
Any sort of safety: https://eng.uber.com/data-race-patterns-in-go/

Go's concurrency model is bog-standard shoot your foot off shared memory.

A channel is not magic, it's a multiple-producer multiple-consumer queue, you can unwittingly send a pointer over it (or a pointer-ish, like a hashmap) and boom you've got unchecked concurrent mutations, and in Go that even opens you up to data races (memory unsafety).

And because channels are slow, it's common to go down the stack, and hit further issues of mis-managing your mutexes or waitgroups, to say nothing of spawning a goroutine by closing over a mutable location.

You can do it right, in the same way you can do it right in C, C++, Java, Ruby, or Python. And arguably it's more difficult in Go because it drives you significantly more towards concurrency (and spawning tons of goroutines) without really giving you better tools to manage it (the only one I can think of is select).

Re:How I went about learning Rust by baby on Friday July 15, 2022 @02:58AM (#32105434)
Long time rust/go dev, go is so much faster to write for web services. For the rest rust is pretty nice.
Re:How I went about learning Rust by cultofmetatron on Friday July 15, 2022 @04:33PM (#32112473)
> I adore Rust for every use case I’ve tried it out for except for network service

thats hilarious, my daily driver language is elixir which is the goat for network services. I saw rust as the perfect compliment for that where I need everything else.

Re:How I went about learning Rust by tofuahdude on Friday July 15, 2022 @02:11AM (#32105124)
Could you please expand on this a bit? What are some example services that would be better written in go vs rust?
Re:How I went about learning Rust by Cthulhu_ on Friday July 15, 2022 @04:28AM (#32106016)
I 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.

Re:How I went about learning Rust by bbkane on Friday July 15, 2022 @11:51AM (#32109373)
You might look into your database's support for JSON columns. Sometimes you can even make indices for expressions on them
Re:How I went about learning Rust by philosopher1234 on Friday July 15, 2022 @12:51PM (#32110148)
sqlc is very go-like, i recommend it.
Re:How I went about learning Rust by mihaigalos on Friday July 15, 2022 @02:10AM (#32105119)
What 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...

Re:How I went about learning Rust by masklinn on Friday July 15, 2022 @02:16AM (#32105151)
> Very nice multi-threading via Go routines and channels. Impressive semantics in simple syntax, requiring no synchronization mechanism on the user side.

Except for all the times they are required and Go doesn’t tell you: https://eng.uber.com/data-race-patterns-in-go/

Go’s fundamental semantics are standard not-safe shared-memory multi threading. It provides an mpmc queue as a built-in out of necessity (since no generics originally, which would have made for an awkward situation), but really the only thing that’s notable about it is `select`, not `go` or `chan`.

In in some ways `go` is even a downgrade from other languages: you can’t get a handle on the goroutine and thus have to muck around with side-channels to even know that a subroutine has terminated let alone get its result.

Re:How I went about learning Rust by philosopher1234 on Friday July 15, 2022 @12:53PM (#32110171)
>In in some ways `go` is even a downgrade from other languages: you can’t get a handle on the goroutine and thus have to muck around with side-channels to even know that a subroutine has terminated let alone get its result.

You sound like you don't know why they explicitly refuse to add the ability to get a handle on the goroutine. If you do know, you are misleading people by omitting it.

Re:How I went about learning Rust by rob74 on Friday July 15, 2022 @02:31AM (#32105251)
My thoughts on your thoughts:

* Go also includes the complete build system, package management (although it wasn't there from the beginning), code documentation, testing and fuzzing. Also the standard library is much more extensive than in Rust ("batteries included").

* Doctests: since you mention them explicitly, Go has those too: https://go.dev/blog/examples

* "Large garbage collector penalty": that obviously depends on your application and what you consider acceptable. I would say that in most cases the easier development enabled by having GC is worth it, but YMMV. Here's a discussion on the Go garbage collector: https://news.ycombinator.com/item?id=12042302

Re:How I went about learning Rust by mihaigalos on Friday July 15, 2022 @02:32AM (#32105263)
Wow, very nice! I didn't know that. I love how the language is evolving, it also now has generics.
Re:How I went about learning Rust by Jyaif on Friday July 15, 2022 @03:28AM (#32105646)
> slow to compile

In my experience it's the slowest language to compile ever, and the binaries generated are gargantuan.

I was super excited to learn Rust, but that excitement is now 100% gone.

Re:How I went about learning Rust by rcxdude on Friday July 15, 2022 @04:19AM (#32105966)
Binary size very much depends on your settings. Rust does not optimise for a small 'hello world' by default, but it's very possible to get small binaries from it if that's a priority for you (for example, the default debug build neither optimizes for size nor strips debug information, as well as statically linking the standard library). Compile times are more sticky problem and most ways to improve it basically involve avoiding certain language features and libraries.
Re:How I went about learning Rust by bbojan on Friday July 15, 2022 @03:55AM (#32105811)
I wonder what other languages you have experience with. C++ is obviously not one of them.
Re:How I went about learning Rust by gg2222 on Friday July 15, 2022 @05:59AM (#32106480)
Same. I was about to jump into learning Rust and make it my no.1 language for new projects instead of node.js + TypeScript, but once I learned about the slow compile times I stopped that thought immediately.
Re:How I went about learning Rust by ModernMech on Friday July 15, 2022 @10:58AM (#32108849)
For me it was a choice between slow compile times now when it’s safe, or unbounded time solving security and stability issues later when it’s critical.
Re:How I went about learning Rust by tofuahdude on Friday July 15, 2022 @02:15AM (#32105145)
How "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.
Re:How I went about learning Rust by mihaigalos on Friday July 15, 2022 @02:24AM (#32105213)
Check 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.

Re:How I went about learning Rust by jhgb on Friday July 15, 2022 @12:56PM (#32110204)
The question here is how much can you disambiguate between the impact of GC and the impact of differently written code plus differently optimizing compiler backend (where Go is still very simple but Rust uses LLVM). If for example the Go code used goroutines and channels in those places where the rewritten Rust code uses asynchronous operations, that alone may account for substantial differences in performance.
Re:How I went about learning Rust by lossolo on Saturday July 16, 2022 @06:39PM (#32122613)
Posting links to his blog post is misleading in 2022. The issue they mention in their blog was fixed so it's not an issue now.
Re:How I went about learning Rust by mihaigalos on Sunday July 17, 2022 @12:58AM (#32124578)
That's interesting. Would like to read about the solution more. Do you have a reference?
Re:How I went about learning Rust by tofuahdude on Friday July 15, 2022 @02:29AM (#32105241)
Just 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.

Re:How I went about learning Rust by masklinn on Friday July 15, 2022 @02:17AM (#32105165)
Go’s GC is not efficient, it is responsive. That is, it trades throughput (and performances, and efficiency) for small pauses and concurrency.
Re:How I went about learning Rust by olalonde on Friday July 15, 2022 @03:53AM (#32105802)
I 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).

Re:How I went about learning Rust by collaborative on Friday July 15, 2022 @02:44AM (#32105336)
I 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

Re:How I went about learning Rust by Jyaif on Friday July 15, 2022 @03:31AM (#32105666)
> 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!

Re:How I went about learning Rust by hyperman1 on Friday July 15, 2022 @05:41AM (#32106386)
I 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.

Re:How I went about learning Rust by zozbot234 on Friday July 15, 2022 @06:03AM (#32106502)
Rust has a stable ABI actually, it's called the C ABI. But since most Rust crates do rely on monomorphized generic code in many ways, it's just not possible to share binary artifacts in the first place. (The situation is similar for "header only" libraries in C++.) If you're writing a library that truly does not involve generic code, it makes total sense to expose it via a pure C interface anyway so that languages other than Rust can make use of it.
Re:How I went about learning Rust by hyperman1 on Friday July 15, 2022 @11:56AM (#32109427)
C ABI is very well supported indeed. After commiting some contortions to avoid varargs, I found out Rust does actually cover them.

But it's still something different than a real rust ABI. Basic things like pushing a string or an enum to a client will hurt. Providing a rust library without source is not an option for now.

Re:How I went about learning Rust by Fiahil on Friday July 15, 2022 @06:55AM (#32106827)
As of Rust 1.62, compilation time is no longer a valid criticism. Things have improved so much in the past 2-3 versions, it's no longer slower than C++. Sorry!
Re:How I went about learning Rust by thesuperbigfrog on Friday July 15, 2022 @09:55AM (#32108248)
>> As of Rust 1.62, compilation time is no longer a valid criticism. Things have improved so much in the past 2-3 versions, it's no longer slower than C++. Sorry!

Is there a report or study somewhere that shows how much it has improved?

I had heard improving compilation and build time was being worked on, but I don't get to use Rust much in my current work.

I would be interested to see how much improvement has been made and in what areas.

Re:How I went about learning Rust by bbkane on Friday July 15, 2022 @04:21PM (#32112330)
Re:How I went about learning Rust by pimeys on Friday July 15, 2022 @11:25AM (#32109099)
There are a few things to make things slow still. Try macros generating async code. That can go out of control and is a common case in tests.
Re:How I went about learning Rust by bbojan on Friday July 15, 2022 @03:51AM (#32105791)
One 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.

Re:How I went about learning Rust by prirun on Friday July 15, 2022 @09:12AM (#32107797)
> 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...

https://github.com/go-python/gopy

Re:How I went about learning Rust by int_19h on Friday July 15, 2022 @04:39PM (#32112547)
Having 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/

(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).

Re:How I went about learning Rust by ActorNightly on Friday July 15, 2022 @02:30AM (#32105245)
Learning 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.

Re:How I went about learning Rust by zozbot234 on Friday July 15, 2022 @02:28AM (#32105235)
Since 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.
Re:How I went about learning Rust by mprovost on Friday July 15, 2022 @05:40AM (#32106376)
I'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/

Re:How I went about learning Rust by cercatrova on Friday July 15, 2022 @10:22AM (#32108494)
Interesting, seems similar to the book Command Line Rust which also teaches you by reimplementing Unix commands, any thoughts on the differences?
Re:How I went about learning Rust by mprovost on Friday July 15, 2022 @11:21AM (#32109052)
Yes I saw that... I released mine first but I'm publishing it a chapter at a time and mine is about half done. I haven't read the O'Reilly one because I don't want to inadvertently copy anything or be influenced by it. I think the main difference between my book and this one is that I go through the original BSD source and translate it into idiomatic Rust. I also teach how to work with the borrow checker without resorting to copy/clone or reference counting which I think is unique. And I don't use lifetimes anywhere in the book - they're an advanced topic that really puts off new Rust programmers and aren't needed in most cases.
Re:How I went about learning Rust by Scarbutt on Friday July 15, 2022 @02:43PM (#32111454)
Nice, is the BSD C source unchanged in the book?
Re:How I went about learning Rust by mprovost on Friday July 15, 2022 @02:54PM (#32111569)
Yes! I use the (final) 4.4 release from 1993. Some were written by Bill Joy! But if you look at the modern OpenBSD or FreeBSD (or MacOS) versions they’re still about 90% unchanged. The older versions are a bit shorter which makes it easier to explain.
Re:How I went about learning Rust by vladvasiliu on Friday July 15, 2022 @03:02AM (#32105460)
I 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.

Re:How I went about learning Rust by olalonde on Friday July 15, 2022 @06:23AM (#32106625)
Reading an entire book on C is probably overkill. This video is probably enough for most beginners: https://www.youtube.com/watch?v=rDoqT-a6UFg
Re:How I went about learning Rust by intelijstupide on Saturday July 16, 2022 @05:40AM (#32116492)
Wow thank's for that link. Bridged a few gaps for me between what I remember from c++ and what I've been learning in rustlings.
Re:How I went about learning Rust by doctor_eval on Friday July 15, 2022 @03:35AM (#32105690)
This 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.

Re:How I went about learning Rust by pizza234 on Friday July 15, 2022 @05:09AM (#32106241)
> 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.

Re:How I went about learning Rust by kouteiheika on Friday July 15, 2022 @05:28AM (#32106322)
> 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.

Re:How I went about learning Rust by gg2222 on Friday July 15, 2022 @06:03AM (#32106500)
What Rust web libraries/frameworks do you use and recommend? How long does your Rust project take to compile?
Re:How I went about learning Rust by kouteiheika on Friday July 15, 2022 @08:20AM (#32107318)
> What Rust web libraries/frameworks do you use and recommend?

This might not be a satisfying answer for you, but I use my own framework. Its main selling point is that it can be compiled in two modes: during development it has zero dependencies and is blazingly fast to compile (it has its own minimal HTTP implementation, its own minimal executor, etc.), and for production it switches to use production-ready crates which everyone else uses (`hyper`, `tokio`, etc.)

Personally I'm not a fan of most frameworks which are commonly used in Rust webdev. The reason for that is twofold:

1) Most of them suffer from what I call the npm-syndrome, with hundreds of dependencies out of the box. Case in point, the minimal example from Warp's readme pulls in 146 crates.

2) They're often really complicated and have a lot of magic. I prefer simple functions with explicit control flow instead of layers upon layers of generics and macros stacked upon each other.

(DISCLAIMER: The following is purely my personal opinion; I'm not saying one approach is objectively better than the other, just stating what I prefer.)

For example, in Warp the way you add compression is by stacking a filter on top of your route:

    let examples = warp::path("ex")
        .and(warp::fs::dir("./examples/"))
        .with(warp::compression::deflate());
In my framework you have an explicit function through which every request goes through, so if want to add compression you just call a function which takes a request and returns it:

    fn deflate(response: Response) -> Response { ... }

    async fn server_main(request: Request) -> Response {
        let response = ...;
        let response = deflate(response);
        //
        return response;
    }
There's no magic and you can clearly see exactly what's going on, and you can also easily add new transformations without the need to become a trait astronaut.
Re:How I went about learning Rust by gg2222 on Friday July 15, 2022 @09:28AM (#32107958)
Amazing! Thanks for explaining that.

I think that's a great solution because the biggest thing that makes me afraid of Rust webdev is compile times. Your solution seems perfect as you can get quick compile times during development.

Re:How I went about learning Rust by intelijstupide on Friday July 15, 2022 @10:26AM (#32108527)
Anywhere you picked this up from I could read more about?

Fellow npm-syndrome avoider.

Re:How I went about learning Rust by memorable on Friday July 15, 2022 @07:18AM (#32106965)
I'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

Re:How I went about learning Rust by cercatrova on Friday July 15, 2022 @10:21AM (#32108482)
Have you tried axum? It's by the Tokio organization, newer than the others.

I still use actix-web though since I found it way easier to parse than axum or warp, in my opinion. The minimal examples for each make actix-web the most readable for me.

Re:How I went about learning Rust by risyachka on Friday July 15, 2022 @05:59AM (#32106483)
For 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.

Re:How I went about learning Rust by greenmana on Friday July 15, 2022 @08:34AM (#32107429)
I'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.
Re:How I went about learning Rust by spicysugar on Friday July 15, 2022 @07:33AM (#32107037)
I 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.

Re:How I went about learning Rust by snoopy_telex on Friday July 15, 2022 @02:51AM (#32105383)
I 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.

Re:How I went about learning Rust by vram22 on Friday July 15, 2022 @04:45AM (#32106124)
>That said, I feel that Rust is likely the winner long term.

Interesting; why do you think so?

Re:How I went about learning Rust by usrusr on Friday July 15, 2022 @02:31AM (#32105250)
I 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.

Re:How I went about learning Rust by kif on Friday July 15, 2022 @04:27AM (#32106006)
If 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.

Re:How I went about learning Rust by oconnor663 on Friday July 15, 2022 @11:25AM (#32109097)
I 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.)
Re:How I went about learning Rust by metadat on Friday July 15, 2022 @01:59AM (#32105059)
If you learn Rust and become proficienct, Go will be comparably trivial.
Re:How I went about learning Rust by mmgutz on Friday July 15, 2022 @05:46AM (#32106411)
For 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.
Re:How I went about learning Rust by ChrisRR on Friday July 15, 2022 @04:08AM (#32105889)
If 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

Re:How I went about learning Rust by Fiahil on Friday July 15, 2022 @06:52AM (#32106812)
> 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 !

Re:How I went about learning Rust by woile on Friday July 15, 2022 @03:47AM (#32105751)
Most 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

Re:How I went about learning Rust by xEnOnn on Friday July 15, 2022 @05:39AM (#32106369)
I 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.

Re:How I went about learning Rust by anon291 on Saturday July 16, 2022 @01:00AM (#32115353)
I 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.
Re:How I went about learning Rust by azeirah on Friday July 15, 2022 @01:55AM (#32105028)
Just thinking out loud, does go compile to WASM? I often see performance critical WASM snippets written in rust, but never in Go.
Re:How I went about learning Rust by Philip-J-Fry on Friday July 15, 2022 @02:01AM (#32105073)
Go 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.

Re:How I went about learning Rust by doctor_eval on Friday July 15, 2022 @03:38AM (#32105708)
TinyGo is great, I used to to program microcontrollers and there wasn’t anything I really missed, though admittedly it was a very small program.
Re:How I went about learning Rust by rob74 on Friday July 15, 2022 @02:01AM (#32105069)
Yes 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
Re:How I went about learning Rust by masklinn on Friday July 15, 2022 @02:03AM (#32105080)
Go 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.
Re:How I went about learning Rust by pjmlp on Friday July 15, 2022 @02:04AM (#32105084)
Hardly an issue when looking at the ads crap that get download in every "modern" site.
Re:How I went about learning Rust by alpaca128 on Friday July 15, 2022 @02:31AM (#32105248)
Sure, 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.
Re:How I went about learning Rust by masklinn on Friday July 15, 2022 @02:18AM (#32105175)
Sure if your use case for go wasm is ads crap knock yourself out.
Re:How I went about learning Rust by pjmlp on Friday July 15, 2022 @02:20AM (#32105190)
That 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.

Re:How I went about learning Rust by prerok on Friday July 15, 2022 @02:04AM (#32105085)
Sure it can: https://golangbot.com/webassembly-using-go/

Never tried it, though :)

Re:How I went about learning Rust by gwbas1c on Friday July 15, 2022 @12:52PM (#32110168)
I 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.

Re:How I went about learning Rust by cultofmetatron on Friday July 15, 2022 @04:29PM (#32112424)
you'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.

Re:How I went about learning Rust by shiomiru on Friday July 15, 2022 @03:05AM (#32105479)
There was a relevant discussion here just a little while ago: https://news.ycombinator.com/item?id=31976407
Re:How I went about learning Rust by devnull3 on Friday July 15, 2022 @01:58AM (#32105051)
> What would be a good use case of Rust than Golang

If you can afford GC in your project go for Golang else Rust.

Re:How I went about learning Rust by nbittich on Friday July 15, 2022 @02:18AM (#32105168)
I 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.

Re:How I went about learning Rust by tlamponi on Friday July 15, 2022 @02:36AM (#32105286)
> but there's no job in

That's just not true.

Rust got already adopted by lot of either big or interesting to work at players (Amazon, Microsoft, DropBox, ...?) and, while anecdotal, I myself get also paid to program rust.

> the community is toxic. > In the rust community, just like a sect, everybody must say that everything is just perfect.

I often get the opposite feeling with all the diverse and lengthy discussions about how to do things, e.g., like getting async stable a few years ago or long blog articles of core contributors that state "we can do a lot better here and there" in public blog posts that get shared on /r/rust and don't get shunned.

Re:How I went about learning Rust by pizza234 on Friday July 15, 2022 @05:12AM (#32106253)
> Rust got already adopted by lot of either big or interesting to work at players (Amazon, Microsoft, DropBox, ...?) and, while anecdotal, I myself get also paid to program rust.

There are very few open positions, though. Just check out the Rust newsletter - the open positions for each release can be counted on one hand.

I have the suspicions that Rust positions are typically filled in-house. Shopify, for example, adopted Rust, but AFAIK they did not hire anybody external to do so (nothing wrong with this, of course).

Re:How I went about learning Rust by tlamponi on Friday July 15, 2022 @05:59AM (#32106482)
> Just check out the Rust newsletter - the open positions for each release can be counted on one hand.

IMO there's only a tiny selection on that newsletter, it's just not a canonical source for rust jobs. E.g. and again anecdotal, we don't post our rust job openings there either as such more widely read publications are seldom a good fit, just like the monthly HN "who's hiring" thread - we don't want a flood of applications whom a good percentage of cannot even bother to read the few basic "must haves" for the job.

Also, in house fillings need employees that can program in rust too.

Re:How I went about learning Rust by pimeys on Friday July 15, 2022 @12:31PM (#32109890)
Our company (Prisma) is currently hiring Rust engineers. Remote jobs, office in Berlin for those who need it and interesting problems to solve.
Re:How I went about learning Rust by vladvasiliu on Friday July 15, 2022 @02:32AM (#32105261)
> Also, the community is toxic.

How so? I've seen the random drama crop up here and there, but it always seemed to mostly be about the "political" side of things, as opposed to the technical development.

What few interactions I've had with library maintainers and the tokio project have always been positive, and the people always seemed helpful.

Re:How I went about learning Rust by hu3 on Friday July 15, 2022 @03:00AM (#32105449)
Comments like this one below are often downvoted without reply just because they criticise rust:

> I founf myself in your same situation a few months ago. I chose Rust and regret it...

https://news.ycombinator.com/item?id=32105336

GP puts it well:

> Just like in any sect. As long as you agree everything is perfect, the community is the friendliest indeed.

The community isn't toxic as long as you happen to agree with it and praise Rust... Go figure.

Re:How I went about learning Rust by Ygg2 on Friday July 15, 2022 @05:41AM (#32106381)
GP is also wrong.

At this point it's mostly a meme. Rust is slow to compile. I mean, yeah if you abuse meta programming or monomorphisation.

I've been programming in it, and while I like the language, I'm not on the language community bandwagon. E.g. CoC and it's enforcement (I think it's just pointless grandstanding).

Re:How I went about learning Rust by zozbot234 on Friday July 15, 2022 @06:13AM (#32106557)
I've seen pretty much zero grandstanding in the Rust community about the CoC. They seem to treat it as any CoC should be treated in practice; a failsafe measure which is most critical for in-person events, and to protect people who make their real-world identity public from aggressive trolling and malicious behavior.
Re:How I went about learning Rust by Ygg2 on Friday July 15, 2022 @06:31AM (#32106668)
First. You are arguing against my sidenote, on why I don't consider myself Rust coolaid member. Second: it's just my opinion.

Third: I said CoC is grandstanding. It's just a toothless document, that pretends to solve issues much like renaming Git default branch master->main.

We saw it wasn't enforceable last year when Rust moderators quit over being unable to enforce it.

Re:How I went about learning Rust by formerly_proven on Friday July 15, 2022 @02:26AM (#32105227)
> Also, the community is toxic.

The Rust community has been the friendliest PL community I've seen so far.

Re:How I went about learning Rust by tome on Saturday July 16, 2022 @04:15AM (#32116147)
There's similar thing about Haskell. I often hear stories like "wow, I'm so glad I found Haskell, the community has been so friendly and helpful" and then other stories like "I tried Haskell and I liked the language but it was just such a toxic community". I don't really know what to make of this, and at this point I just put it down to the infinite variety in human experiences and preferences.
Re:How I went about learning Rust by nbittich on Friday July 15, 2022 @02:33AM (#32105270)
Just like in any sect. As long as you agree everything is perfect, the community is the friendliest indeed.
Re:How I went about learning Rust by pkolaczk on Friday July 15, 2022 @03:10AM (#32105511)
Nope, 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.

Re:How I went about learning Rust by Ygg2 on Friday July 15, 2022 @05:43AM (#32106396)
That's not fair to Rust. I think it's feature of community size and genuine interest/innovation in Rust.
Re:How I went about learning Rust by gary17the on Friday July 15, 2022 @03:19AM (#32105588)
> there's no job in [Rust]

As of today, indeed.com lists 1,500 remote jobs mentioning Rust vs. 4,018 jobs mentioning Golang. That's not so bad. (However, there's no way to tell how many of those listings are Rust-specific as opposed to polyglot job descriptions.)

> Also, the [Rust] community is toxic.

Speaking slightly humorously, if you think Rust community is toxic, try expressing your dissatisfaction with Swift or Apple in the fanboi Swift community (controlled by Apple employees) and see what happens to you :).

Re:How I went about learning Rust by zozbot234 on Friday July 15, 2022 @03:45AM (#32105740)
Most "jobs mentioning Rust" are in the crypto space for some reason. I can't fault devs for thinking that such "opportunities" are just not very serious compared to the alternatives.
Re:How I went about learning Rust by rapsey on Friday July 15, 2022 @04:17AM (#32105949)
Every one of the big tech companies have large Rust projects. Even Apple has open job listings for Rust devs.
Re:How I went about learning Rust by gary17the on Friday July 15, 2022 @04:29AM (#32106021)
I agree that crypto indeed started out as a dumb, speculative, monetary technology, but it is currently moving toward smart-contract, non-speculative applications, such as guaranteed voting or transfer-of-ownership systems. Crypto indeed started out as a nonsensically power-hungry technology (via Proof-of-Work), but it is currently moving toward power-friendly infrastructure (via Proof-of-Stake). I think the crypto sector will slowly become more and more interesting, employment-wise. For example, how about writing a single contract that is understandable not only by a machine, but also, at the same time, by a judge in a court of law?
Re:How I went about learning Rust by Shorel on Friday July 15, 2022 @06:17AM (#32106579)
Development is development.

Video games are not "serious", yet any C++ developer getting their chops in video game programming is not shunned for it.

Re:How I went about learning Rust by boris on Friday July 15, 2022 @03:11AM (#32105519)
> Also, the community is toxic.

I think "somewhat dogmatic" would be a more accurate description of the Rust community, IMO.

For example, I recently had a discussion about `enum` being a poor choice for what Rust makes it to mean from a C/C++ developer's point of view (which are Rust's main "replacement target" languages). The closest I got someone to agreeing with me is a sentiment along these lines "well, `variant` would may have been a better choice but it's not very familiar to C/C++ developers and, besides, when this decision was made, Rust had a hard limit of 5 characters on keyword length".

Re:How I went about learning Rust by estebank on Friday July 15, 2022 @11:46PM (#32115066)
FWIW, changing the keyword and nomenclature for such a fundamental part of the language after so much time has passed is... not realistic. Any conversation around it is bound to be somewhat fraught, and happens often enough that people have gone over it and aren't particularly keen to retread it. To the person starting the conversation it might seem like people are handwaving away arguments or being dismissive.
Re:How I went about learning Rust by whostolemyhat on Friday July 15, 2022 @10:59AM (#32108854)
> Also, the community is toxic.

I've found the complete opposite, Rust communities are the least hostile programming environments I've come across.

There's also a huge amount of irony about saying a community is toxic on this site

Re:How I went about learning Rust by anon291 on Saturday July 16, 2022 @01:03AM (#32115368)
This is wild to me as someone who spent many years in Haskell and made shit tons of money doing it. There are myriad Haskell jobs available. I'm taking a break right now (mainly to pick up other skills), but would go back to it in a heartbeat. There are lots of Haskell jobs.